binread

Struct PosValue

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

A wrapper where the position it was read from is stored alongside the value

use binread::{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§pos: u64

Trait Implementations§

source§

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

source§

type Args = <T as BinRead>::Args

The type of arguments needed to be supplied in order to read this type, usually a tuple. Read more
source§

fn read_options<R: Read + Seek>( reader: &mut R, options: &ReadOptions, args: T::Args, ) -> BinResult<Self>

Read the type from the reader
source§

fn after_parse<R: Read + Seek>( &mut self, reader: &mut R, options: &ReadOptions, args: Self::Args, ) -> BinResult<()>

source§

fn read<R: Read + Seek>(reader: &mut R) -> BinResult<Self>

Read the type from the reader while assuming no arguments have been passed Read more
source§

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

Read the type from the reader using the specified arguments
source§

fn args_default() -> Option<Self::Args>

The default arguments to be used when using the read shortcut method. Override this for any type that optionally requries arguments
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> 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

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

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Deref for PosValue<T>

source§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.

Auto Trait Implementations§

§

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

§

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 T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 T
where 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 T
where T: Clone,

source§

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 T
where U: Into<T>,

source§

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 T
where U: TryFrom<T>,

source§

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.