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.
pub fn parse_with<R, F, Args>(
parser: F
) -> impl Fn(&mut R, &ReadOptions, Args) -> BinResult<T> where
R: Read + Seek,
Args: Clone,
F: Fn(&mut R, &ReadOptions, Args) -> BinResult<T>,
pub fn parse_with<R, F, Args>(
parser: F
) -> impl Fn(&mut R, &ReadOptions, Args) -> BinResult<T> where
R: Read + Seek,
Args: Clone,
F: Fn(&mut R, &ReadOptions, Args) -> BinResult<T>,
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
fn read_options<R: Read + Seek>(
reader: &mut R,
options: &ReadOptions,
_: Self::Args
) -> BinResult<Self>
fn read_options<R: Read + Seek>(
reader: &mut R,
options: &ReadOptions,
_: Self::Args
) -> BinResult<Self>
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,
fn after_parse<R>(
&mut self,
reader: &mut R,
ro: &ReadOptions,
args: BR::Args
) -> BinResult<()> where
R: Read + Seek,
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.
Dereferences the value.
Panics
Will panic if FilePtr
hasn’t been finalized by calling
after_parse()
.
Panics
Will panic if the FilePtr has not been read yet using BinRead::after_parse