pub struct VecArgs<Inner: Clone> {
pub count: usize,
pub inner: Inner,
}
Expand description
Named arguments for the BinRead::read_options()
implementation of Vec
.
§Examples
use binrw::{BinRead, io::Cursor};
#[derive(BinRead)]
#[br(little)]
struct Collection {
count: u16,
#[br(args {
count: count.into(),
inner: ElementBinReadArgs { count: 2 },
})]
elements: Vec<Element>,
}
#[derive(BinRead)]
#[br(import { count: usize })]
struct Element(#[br(args {
count,
inner: <_>::default(),
})] Vec<u8>);
assert_eq!(
Collection::read(&mut Cursor::new(b"\x03\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])
]
}
)
The inner
field can be omitted completely if the inner type doesn’t
require arguments, in which case a default value will be used:
#[derive(BinRead)]
struct Collection {
count: u16,
#[br(args { count: count.into() })]
elements: Vec<u32>,
}
Fields§
§count: usize
The number of elements to read.
inner: Inner
The arguments for the inner type.
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<Inner> Freeze for VecArgs<Inner>where
Inner: Freeze,
impl<Inner> RefUnwindSafe for VecArgs<Inner>where
Inner: RefUnwindSafe,
impl<Inner> Send for VecArgs<Inner>where
Inner: Send,
impl<Inner> Sync for VecArgs<Inner>where
Inner: Sync,
impl<Inner> Unpin for VecArgs<Inner>where
Inner: Unpin,
impl<Inner> UnwindSafe for VecArgs<Inner>where
Inner: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)