Struct binrw::FilePtr[][src]

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

A wrapper type which represents a layer of indirection within a file.

FilePtr<P, T> is composed of two types. The pointer type P is the absolute offset to a value within the data, and the value type T is the actual pointed-to value. Once a FilePtr has been finalized, dereferencing it will yield the pointed-to value.

When deriving BinRead, offset directives can be used to adjust the offset before the pointed-to value is read.

Examples

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

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

Example data mapped out:

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

Fields

ptr: Ptr

The raw offset to the value.

value: Option<BR>

The pointed-to value.

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 for use with the parse_with directive that reads and then immediately finalizes a FilePtr, returning the pointed-to value as the result.

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

Consumes this object, returning the pointed-to value.

Panics

Will panic if FilePtr hasn’t been finalized by calling after_parse().

Trait Implementations

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

type Args = BR::Args

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

fn read_options<R: Read + Seek>(
    reader: &mut R,
    options: &ReadOptions,
    _: Self::Args
) -> BinResult<Self>
[src]

Reads the offset of the value from the reader.

The actual value will not be read until after_parse() is called.

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

Finalizes the FilePtr by seeking to and reading the pointed-to value.

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]

Dereferences the value.

Panics

Will panic if FilePtr hasn’t been finalized by calling 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.