Struct binrw::PosValue

source ·
pub struct PosValue<T> {
    pub val: T,
    pub pos: u64,
}
Expand description

A wrapper that stores a value’s position alongside the value.

Examples

use binrw::{BinRead, PosValue, BinReaderExt, io::Cursor};

#[derive(BinRead)]
struct MyType {
    a: u16,
    b: PosValue<u8>
}

let val = Cursor::new(b"\xFF\xFE\xFD").read_be::<MyType>().unwrap();
assert_eq!(val.b.pos, 2);
assert_eq!(*val.b, 0xFD);

Fields§

§val: T

The read value.

§pos: u64

The byte position of the start of the value.

Trait Implementations§

source§

impl<T: BinRead> BinRead for PosValue<T>

§

type Args<'a> = <T as BinRead>::Args<'a>

The type used for the args parameter of read_args() and read_options(). Read more
source§

fn read_options<R: Read + Seek>( reader: &mut R, endian: Endian, args: Self::Args<'_> ) -> BinResult<Self>

Read Self from the reader using the given Endian and arguments. Read more
source§

fn after_parse<R: Read + Seek>( &mut self, reader: &mut R, endian: Endian, args: Self::Args<'_> ) -> BinResult<()>

Runs any post-processing steps required to finalize construction of the object. Read more
source§

fn read_be_args<R: Read + Seek>( reader: &mut R, args: Self::Args<'_> ) -> BinResult<Self>

Read Self from the reader, assuming big-endian byte order, using the given arguments. Read more
source§

fn read_le_args<R: Read + Seek>( reader: &mut R, args: Self::Args<'_> ) -> BinResult<Self>

Read Self from the reader, assuming little-endian byte order, using the given arguments. Read more
source§

fn read_ne_args<R: Read + Seek>( reader: &mut R, args: Self::Args<'_> ) -> BinResult<Self>

Read T from the reader, assuming native-endian byte order, using the given arguments. Read more
source§

impl<T: Clone> Clone for PosValue<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for PosValue<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Deref for PosValue<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<T> DerefMut for PosValue<T>

source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
source§

impl<U, T: PartialEq<U>> PartialEq<U> for PosValue<T>

source§

fn eq(&self, other: &U) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for PosValue<T>where T: RefUnwindSafe,

§

impl<T> Send for PosValue<T>where T: Send,

§

impl<T> Sync for PosValue<T>where T: Sync,

§

impl<T> Unpin for PosValue<T>where T: Unpin,

§

impl<T> UnwindSafe for PosValue<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.