Function binrw::helpers::count

source ·
pub fn count<R, T, Arg, Ret>(
    n: usize,
) -> impl Fn(&mut R, Endian, Arg) -> BinResult<Ret>
where T: for<'a> BinRead<Args<'a> = Arg>, R: Read + Seek, Arg: Clone, Ret: FromIterator<T> + 'static,
Expand description

Creates a parser that reads N items into a collection.

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

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

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