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: Ptr
value: Option<BR>
Implementations
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
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>
Read the type from the reader
fn after_parse<R>(
&mut self,
reader: &mut R,
ro: &ReadOptions,
args: BR::Args
) -> BinResult<()> where
R: Read + Seek,
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
Panics
Will panic if the FilePtr has not been read yet using BinRead::after_parse
Panics
Will panic if the FilePtr has not been read yet using BinRead::after_parse