pub trait BinReaderExt:
Read
+ Seek
+ Sized {
// Provided methods
fn read_type<T: BinRead>(&mut self, endian: Endian) -> BinResult<T> { ... }
fn read_be<T: BinRead>(&mut self) -> BinResult<T> { ... }
fn read_le<T: BinRead>(&mut self) -> BinResult<T> { ... }
fn read_ne<T: BinRead>(&mut self) -> BinResult<T> { ... }
fn read_type_args<T: BinRead>(
&mut self,
endian: Endian,
args: T::Args,
) -> BinResult<T> { ... }
fn read_be_args<T: BinRead>(&mut self, args: T::Args) -> BinResult<T> { ... }
fn read_le_args<T: BinRead>(&mut self, args: T::Args) -> BinResult<T> { ... }
fn read_ne_args<T: BinRead>(&mut self, args: T::Args) -> BinResult<T> { ... }
}
Expand description
An extension trait for io::Read
to provide methods for reading a value directly
§Example
use binread::prelude::*; // BinReadExt is in the prelude
use binread::endian::LE;
use binread::io::Cursor;
let mut reader = Cursor::new(b"\x07\0\0\0\xCC\0\0\x05");
let x: u32 = reader.read_le().unwrap();
let y: u16 = reader.read_type(LE).unwrap();
let z = reader.read_be::<u16>().unwrap();
assert_eq!((x, y, z), (7u32, 0xCCu16, 5u16));
Provided Methods§
sourcefn read_type<T: BinRead>(&mut self, endian: Endian) -> BinResult<T>
fn read_type<T: BinRead>(&mut self, endian: Endian) -> BinResult<T>
Read the given type from the reader using the given endianness.
sourcefn read_be<T: BinRead>(&mut self) -> BinResult<T>
fn read_be<T: BinRead>(&mut self) -> BinResult<T>
Read the given type from the reader with big endian byteorder
sourcefn read_le<T: BinRead>(&mut self) -> BinResult<T>
fn read_le<T: BinRead>(&mut self) -> BinResult<T>
Read the given type from the reader with little endian byteorder
sourcefn read_ne<T: BinRead>(&mut self) -> BinResult<T>
fn read_ne<T: BinRead>(&mut self) -> BinResult<T>
Read the given type from the reader with the native byteorder
sourcefn read_type_args<T: BinRead>(
&mut self,
endian: Endian,
args: T::Args,
) -> BinResult<T>
fn read_type_args<T: BinRead>( &mut self, endian: Endian, args: T::Args, ) -> BinResult<T>
Read T
from the reader with the given byte order and arguments.
sourcefn read_be_args<T: BinRead>(&mut self, args: T::Args) -> BinResult<T>
fn read_be_args<T: BinRead>(&mut self, args: T::Args) -> BinResult<T>
Read T
from the reader, assuming big-endian byte order, using the
given arguments.
sourcefn read_le_args<T: BinRead>(&mut self, args: T::Args) -> BinResult<T>
fn read_le_args<T: BinRead>(&mut self, args: T::Args) -> BinResult<T>
Read T
from the reader, assuming little-endian byte order, using the
given arguments.
sourcefn read_ne_args<T: BinRead>(&mut self, args: T::Args) -> BinResult<T>
fn read_ne_args<T: BinRead>(&mut self, args: T::Args) -> BinResult<T>
Read T
from the reader, assuming native-endian byte order, using the
given arguments.
Object Safety§
This trait is not object safe.