BinReaderExt

Trait BinReaderExt 

Source
pub trait BinReaderExt:
    Read
    + Seek
    + Sized {
    // Provided methods
    fn read_type<'a, T>(&mut self, endian: Endian) -> BinResult<T>
       where T: BinRead,
             T::Args<'a>: Required { ... }
    fn read_be<'a, T>(&mut self) -> BinResult<T>
       where T: BinRead,
             T::Args<'a>: Required { ... }
    fn read_le<'a, T>(&mut self) -> BinResult<T>
       where T: BinRead,
             T::Args<'a>: Required { ... }
    fn read_ne<'a, T>(&mut self) -> BinResult<T>
       where T: BinRead,
             T::Args<'a>: Required { ... }
    fn read_type_args<T>(
        &mut self,
        endian: Endian,
        args: T::Args<'_>,
    ) -> BinResult<T>
       where T: BinRead { ... }
    fn read_be_args<T>(&mut self, args: T::Args<'_>) -> BinResult<T>
       where T: BinRead { ... }
    fn read_le_args<T>(&mut self, args: T::Args<'_>) -> BinResult<T>
       where T: BinRead { ... }
    fn read_ne_args<T>(&mut self, args: T::Args<'_>) -> BinResult<T>
       where T: BinRead { ... }
}
Expand description

Extension methods for reading BinRead objects directly from a reader.

§Examples

use binrw::{BinReaderExt, Endian, 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(Endian::Little).unwrap();
let z = reader.read_be::<u16>().unwrap();

assert_eq!((x, y, z), (7u32, 0xCCu16, 5u16));

Provided Methods§

Source

fn read_type<'a, T>(&mut self, endian: Endian) -> BinResult<T>
where T: BinRead, T::Args<'a>: Required,

Read T from the reader with the given byte order.

§Errors

If reading fails, an Error variant will be returned.

Source

fn read_be<'a, T>(&mut self) -> BinResult<T>
where T: BinRead, T::Args<'a>: Required,

Read T from the reader assuming big-endian byte order.

§Errors

If reading fails, an Error variant will be returned.

Source

fn read_le<'a, T>(&mut self) -> BinResult<T>
where T: BinRead, T::Args<'a>: Required,

Read T from the reader assuming little-endian byte order.

§Errors

If reading fails, an Error variant will be returned.

Source

fn read_ne<'a, T>(&mut self) -> BinResult<T>
where T: BinRead, T::Args<'a>: Required,

Read T from the reader assuming native-endian byte order.

§Errors

If reading fails, an Error variant will be returned.

Source

fn read_type_args<T>( &mut self, endian: Endian, args: T::Args<'_>, ) -> BinResult<T>
where T: BinRead,

Read T from the reader with the given byte order and arguments.

§Errors

If reading fails, an Error variant will be returned.

Source

fn read_be_args<T>(&mut self, args: T::Args<'_>) -> BinResult<T>
where T: BinRead,

Read T from the reader, assuming big-endian byte order, using the given arguments.

§Errors

If reading fails, an Error variant will be returned.

Source

fn read_le_args<T>(&mut self, args: T::Args<'_>) -> BinResult<T>
where T: BinRead,

Read T from the reader, assuming little-endian byte order, using the given arguments.

§Errors

If reading fails, an Error variant will be returned.

Source

fn read_ne_args<T>(&mut self, args: T::Args<'_>) -> BinResult<T>
where T: BinRead,

Read T from the reader, assuming native-endian byte order, using the given arguments.

§Errors

If reading fails, an Error variant will be returned.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<R: Read + Seek + Sized> BinReaderExt for R