Struct binread::FilePtr[][src]

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

Implementations

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

Consume the pointer and return the inner type

Panics

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

Trait Implementations

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

Read the type from the reader

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

Read the type from the reader using the specified arguments

The default arguments to be used when using the read shortcut method. Override this for any type that optionally requries arguments Read more

Formats the value using the given formatter. Read more

Panics

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

The resulting type after dereferencing.

Dereferences the value.

Panics

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

Mutably dereferences the value.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.