Struct binread::file_ptr::FilePtr[][src]

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

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: Ptrvalue: Option<BR>

Implementations

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

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

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

pub fn into_inner(self) -> BR[src]

Consume the pointer and return the inner type

Panics

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

Trait Implementations

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

type Args = BR::Args

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

impl<Ptr, BR> Debug for FilePtr<Ptr, BR> where
    Ptr: BinRead<Args = ()> + IntoSeekFrom,
    BR: BinRead + Debug
[src]

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

Panics

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

type Target = BR

The resulting type after dereferencing.

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

Panics

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

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

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.