Struct binrw::FilePtr[][src]

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

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<T>

The pointed-to value.

Implementations

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.

Custom parser for use with the parse_with directive that reads and then immediately finalizes a FilePtr using the specified parser, returning the pointed-to value as the result.

Custom parser for use with the parse_with directive that reads and then immediately finalizes a FilePtr using the specified parser, returning the FilePtr as the result.

Consumes this object, returning the pointed-to value.

Panics

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

Trait Implementations

Reads the offset of the value from the reader.

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

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

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

Read Self from the reader using default arguments.

Read Self from the reader using the given arguments.

Formats the value using the given formatter. Read more

Dereferences the value.

Panics

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