pub struct VecArgs<B> {
pub count: usize,
pub inner: B,
}Expand description
Arguments passed to the binread impl for Vec
Examples
use binrw::{BinRead, io::Cursor};
#[derive(BinRead, Debug, PartialEq)]
struct Collection {
count: u32,
#[br(args { count: count as usize, inner: ElementBinReadArgs { count: 2 } })]
elements: Vec<Element>,
}
#[derive(BinRead, Debug, PartialEq)]
#[br(import { count: u32 })]
struct Element(#[br(args { count: count as usize, inner: () })] Vec<u8>);
assert_eq!(
Collection::read(&mut Cursor::new(b"\x03\0\0\0\x04\0\x05\0\x06\0")).unwrap(),
Collection {
count: 3,
elements: vec![
Element(vec![4, 0]),
Element(vec![5, 0]),
Element(vec![6, 0])
]
}
)Inner types that don’t require args take unit args.
#[derive(BinRead)]
struct Collection {
count: u32,
#[br(args { count: count as usize, inner: () })]
elements: Vec<u32>,
}Unit args for the inner type can be omitted. The count attribute also assumes unit args for the inner type.
#[derive(BinRead)]
struct Collection {
count: u32,
#[br(args { count: count as usize })]
elements: Vec<u32>,
}Fields
count: usizeThe number of elements to read.
inner: BArguments to pass to the inner type
Implementations
sourceimpl<B> VecArgs<B>
impl<B> VecArgs<B>
sourcepub fn builder() -> VecArgsBuilder<B, Needed, Needed>
pub fn builder() -> VecArgsBuilder<B, Needed, Needed>
An inherent method version of BinrwNamedArgs,
designed for use with binrw::args!.
Trait Implementations
sourceimpl<B> BinrwNamedArgs for VecArgs<B>
impl<B> BinrwNamedArgs for VecArgs<B>
Auto Trait Implementations
impl<B> RefUnwindSafe for VecArgs<B> where
B: RefUnwindSafe,
impl<B> Send for VecArgs<B> where
B: Send,
impl<B> Sync for VecArgs<B> where
B: Sync,
impl<B> Unpin for VecArgs<B> where
B: Unpin,
impl<B> UnwindSafe for VecArgs<B> where
B: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more