Function binrw::helpers::until_exclusive_with

source ·
pub fn until_exclusive_with<Reader, T, CondFn, Arg, ReadFn, Ret>(
    cond: CondFn,
    read: ReadFn,
) -> impl Fn(&mut Reader, Endian, Arg) -> BinResult<Ret>
where Reader: Read + Seek, CondFn: Fn(&T) -> bool, Arg: Clone, ReadFn: Fn(&mut Reader, Endian, Arg) -> BinResult<T>, Ret: FromIterator<T>,
Expand description

Creates a parser that uses a given function to read items into a collection until a condition is met. The terminal item is discarded.

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

This helper can be used to read into any collection type that implements FromIterator.

§Examples

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

#[derive(BinRead)]
struct NullTerminated {
    #[br(parse_with = until_exclusive_with(|bytes| bytes == &[0, 0], count(2)))]
    data: VecDeque<VecDeque<u8>>,
}