binread

Struct FilePtr

Source
pub struct FilePtr<Ptr: IntoSeekFrom, BR: BinRead> {
    pub ptr: Ptr,
    pub value: Option<BR>,
}
Expand description

A wrapper type for representing a layer of indirection within a file.

A FilePtr<P, T> is composed of two types: a pointer type P and a value type T where the pointer type describes and offset to read the value type from. Once read from the file it can be dereferenced to yeild the value it points to.

§Example

use binread::{prelude::*, io::Cursor, FilePtr};

#[derive(BinRead)]
struct Test {
    pointer: FilePtr<u32, u8>
}

let test: Test = Cursor::new(b"\0\0\0\x08\0\0\0\0\xff").read_be().unwrap();
assert_eq!(test.pointer.ptr, 8);
assert_eq!(*test.pointer, 0xFF);

Example data mapped out:

          [pointer]           [value]
00000000: 0000 0008 0000 0000 ff                   ............

Use offset to change what the pointer is relative to (default: beginning of reader).

Fields§

§ptr: Ptr§value: Option<BR>

Implementations§

Source§

impl<Ptr: BinRead<Args = ()> + IntoSeekFrom, BR: BinRead> FilePtr<Ptr, BR>

Source

pub fn parse<R: Read + Seek>( reader: &mut R, options: &ReadOptions, args: BR::Args, ) -> BinResult<BR>

Custom parser designed for use with the parse_with attribute (example) that reads a FilePtr then immediately dereferences it into an owned value

Source

pub fn into_inner(self) -> BR

Consume the pointer and return the inner type

§Panics

Will panic if the file pointer hasn’t been properly postprocessed

Trait Implementations§

Source§

impl<Ptr: BinRead<Args = ()> + IntoSeekFrom, BR: BinRead> BinRead for FilePtr<Ptr, BR>

Source§

type Args = <BR 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, _: Self::Args, ) -> BinResult<Self>

Read the type from the reader
Source§

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

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<Ptr, BR> Debug for FilePtr<Ptr, BR>
where Ptr: BinRead<Args = ()> + IntoSeekFrom, BR: BinRead + Debug,

Source§

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

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

impl<Ptr: IntoSeekFrom, BR: BinRead> Deref for FilePtr<Ptr, BR>

§Panics

Will panic if the FilePtr has not been read yet using BinRead::after_parse

Source§

type Target = BR

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<Ptr: IntoSeekFrom, BR: BinRead> DerefMut for FilePtr<Ptr, BR>

§Panics

Will panic if the FilePtr has not been read yet using BinRead::after_parse

Source§

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

Mutably dereferences the value.
Source§

impl<Ptr, BR> PartialEq for FilePtr<Ptr, BR>
where Ptr: BinRead<Args = ()> + IntoSeekFrom, BR: BinRead + PartialEq,

Source§

fn eq(&self, other: &Self) -> 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.

Auto Trait Implementations§

§

impl<Ptr, BR> Freeze for FilePtr<Ptr, BR>
where Ptr: Freeze, BR: Freeze,

§

impl<Ptr, BR> RefUnwindSafe for FilePtr<Ptr, BR>
where Ptr: RefUnwindSafe, BR: RefUnwindSafe,

§

impl<Ptr, BR> Send for FilePtr<Ptr, BR>
where Ptr: Send, BR: Send,

§

impl<Ptr, BR> Sync for FilePtr<Ptr, BR>
where Ptr: Sync, BR: Sync,

§

impl<Ptr, BR> Unpin for FilePtr<Ptr, BR>
where Ptr: Unpin, BR: Unpin,

§

impl<Ptr, BR> UnwindSafe for FilePtr<Ptr, BR>
where Ptr: UnwindSafe, BR: 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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.