pub fn until<Reader, T, CondFn, Arg, Ret>(
cond: CondFn
) -> impl Fn(&mut Reader, Endian, Arg) -> BinResult<Ret>where
T: for<'a> BinRead<Args<'a> = Arg>,
Reader: Read + Seek,
CondFn: Fn(&T) -> bool,
Arg: Clone,
Ret: FromIterator<T>,
Expand description
Creates a parser that reads items into a collection until a condition is met. The terminal item is added to the collection.
This helper can be used to read into any collection type that implements
FromIterator
.
Examples
#[derive(BinRead)]
struct NullTerminated {
#[br(parse_with = until(|&byte| byte == 0))]
data: Vec<u8>,
}