Function binrw::file_ptr::parse_from_iter_with
source · pub fn parse_from_iter_with<Ptr, Value, Ret, Args, It, F, Reader>(
it: It,
parser: F,
) -> impl FnOnce(&mut Reader, Endian, Args) -> BinResult<Ret>where
Ptr: IntoSeekFrom,
Ret: FromIterator<Value>,
Args: Clone,
It: IntoIterator<Item = Ptr>,
F: Fn(&mut Reader, Endian, Args) -> BinResult<Value>,
Reader: Read + Seek,
Expand description
Creates a parser that reads a collection of values from an iterator of
file offsets using the given parser
function.
Offsets are treated as relative to the position of the reader when
parsing begins. Use the seek_before
directive to reposition the
stream in this case.
See the module documentation for more information on how
to use parse_from_iter_with
.
§Examples
#[derive(BinRead)]
#[br(big)]
struct Header {
count: u16,
#[br(args { count: count.into() })]
offsets: Vec<u16>,
}
struct Item(u8);
#[derive(BinRead)]
#[br(big)]
struct Object {
header: Header,
#[br(parse_with = binrw::file_ptr::parse_from_iter_with(header.offsets.iter().copied(), |reader, endian, args| {
u8::read_options(reader, endian, args).map(Item)
}))]
values: Vec<Item>,
}