Function binrw::helpers::count_with

source ·
pub fn count_with<R, T, Arg, ReadFn, Ret>(
    n: usize,
    read: ReadFn,
) -> impl Fn(&mut R, Endian, Arg) -> BinResult<Ret>
where R: Read + Seek, Arg: Clone, ReadFn: Fn(&mut R, Endian, Arg) -> BinResult<T>, Ret: FromIterator<T> + 'static,
Expand description

Creates a parser that uses a given function to read N items into a collection.

The given read function should return one item each time it is called.

This helper is similar to using #[br(count = N)] with Vec, but is more generic so can be used to read into any collection type that implements FromIterator.

§Examples

Reading a two-dimensional VecDeque by combining count_with and count:

#[derive(BinRead)]
struct CountBytes {
    len: u8,

    #[br(parse_with = count_with(len as usize, count(2)))]
    data: VecDeque<VecDeque<u8>>,
}