Skip to main content

BinReader

Struct BinReader 

Source
pub struct BinReader<'a> { /* private fields */ }
Expand description

Cursor-style binary reader, the inverse of BinWriter.

Implementations§

Source§

impl<'a> BinReader<'a>

Source

pub const fn new(src: &'a [u8]) -> Self

New reader.

Source

pub const fn remaining(&self) -> usize

Bytes remaining.

Source

pub const fn is_empty(&self) -> bool

true if the cursor is at end-of-input.

Source

pub const fn pos(&self) -> usize

Current byte offset.

Source

pub fn u8(&mut self) -> Result<u8, SnapshotError>

Read one byte.

§Errors

Returns SnapshotError::Eof on EOF.

Source

pub fn u16(&mut self) -> Result<u16, SnapshotError>

Read a u16 little-endian.

§Errors

Returns SnapshotError::Eof on EOF.

Source

pub fn u32(&mut self) -> Result<u32, SnapshotError>

Read a u32 little-endian.

§Errors

Returns SnapshotError::Eof on EOF.

Source

pub fn u64(&mut self) -> Result<u64, SnapshotError>

Read a u64 little-endian.

§Errors

Returns SnapshotError::Eof on EOF.

Source

pub fn i16(&mut self) -> Result<i16, SnapshotError>

Read an i16 little-endian.

§Errors

Returns SnapshotError::Eof on EOF.

Source

pub fn bool(&mut self) -> Result<bool, SnapshotError>

Read a bool (any non-zero byte counts as true).

§Errors

Returns SnapshotError::Eof on EOF.

Source

pub fn take(&mut self, n: usize) -> Result<&'a [u8], SnapshotError>

Read n bytes (returns a borrowed slice).

§Errors

Returns SnapshotError::Eof on EOF.

Source

pub fn read_into(&mut self, dst: &mut [u8]) -> Result<(), SnapshotError>

Read into a fixed-length destination.

§Errors

Returns SnapshotError::Eof on EOF.

Source

pub fn lp_bytes(&mut self) -> Result<&'a [u8], SnapshotError>

Read a length-prefixed byte slice (u32 le length followed by the bytes).

§Errors

Returns SnapshotError::Eof on EOF.

Trait Implementations§

Source§

impl<'a> Debug for BinReader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for BinReader<'a>

§

impl<'a> RefUnwindSafe for BinReader<'a>

§

impl<'a> Send for BinReader<'a>

§

impl<'a> Sync for BinReader<'a>

§

impl<'a> Unpin for BinReader<'a>

§

impl<'a> UnsafeUnpin for BinReader<'a>

§

impl<'a> UnwindSafe for BinReader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.