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§
Source§impl<Ptr: BinRead<Args = ()> + IntoSeekFrom, BR: BinRead> FilePtr<Ptr, BR>
impl<Ptr: BinRead<Args = ()> + IntoSeekFrom, BR: BinRead> FilePtr<Ptr, BR>
Trait Implementations§
Source§impl<Ptr: BinRead<Args = ()> + IntoSeekFrom, BR: BinRead> BinRead for FilePtr<Ptr, BR>
impl<Ptr: BinRead<Args = ()> + IntoSeekFrom, BR: BinRead> BinRead for FilePtr<Ptr, BR>
Source§type Args = <BR as BinRead>::Args
type Args = <BR as BinRead>::Args
The type of arguments needed to be supplied in order to read this type, usually a tuple. Read more
Source§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<()>
Source§fn read<R: Read + Seek>(reader: &mut R) -> BinResult<Self>
fn read<R: Read + Seek>(reader: &mut R) -> BinResult<Self>
Read the type from the reader while assuming no arguments have been passed Read more
Source§impl<Ptr: IntoSeekFrom, BR: BinRead> Deref for FilePtr<Ptr, BR>
impl<Ptr: IntoSeekFrom, BR: BinRead> Deref for FilePtr<Ptr, BR>
§Panics
Will panic if the FilePtr has not been read yet using BinRead::after_parse
Source§impl<Ptr: IntoSeekFrom, BR: BinRead> DerefMut for FilePtr<Ptr, BR>
impl<Ptr: IntoSeekFrom, BR: BinRead> DerefMut for FilePtr<Ptr, BR>
§Panics
Will panic if the FilePtr has not been read yet using BinRead::after_parse
Auto Trait Implementations§
impl<Ptr, BR> Freeze for FilePtr<Ptr, BR>
impl<Ptr, BR> RefUnwindSafe for FilePtr<Ptr, BR>where
Ptr: RefUnwindSafe,
BR: RefUnwindSafe,
impl<Ptr, BR> Send for FilePtr<Ptr, BR>
impl<Ptr, BR> Sync for FilePtr<Ptr, BR>
impl<Ptr, BR> Unpin for FilePtr<Ptr, BR>
impl<Ptr, BR> UnwindSafe for FilePtr<Ptr, BR>where
Ptr: UnwindSafe,
BR: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more