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: usize

The number of elements to read.

inner: B

Arguments to pass to the inner type

Implementations

An inherent method version of BinrwNamedArgs, designed for use with binrw::args!.

Trait Implementations

The initial builder type from which this type can be constructed

A method for creating a new builder to construct this type from

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.