Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<'a> {
    pub offset: usize,
    /* private fields */
}
Expand description

Sequential reader borrowing a byte slice.

Fields§

§offset: usize

Current byte offset.

Implementations§

Source§

impl<'a> Reader<'a>

Source

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

Borrow input without copying or mutating it.

Source

pub fn remaining(&self) -> usize

Unconsumed byte count.

Source

pub fn raw(&mut self, size: usize) -> Result<&'a [u8]>

Read a bounded range, returning an error rather than panicking.

Source

pub fn fail<T>(&self, message: impl Into<String>) -> Result<T>

Construct a diagnostic at the current position.

Source

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

Read an unsigned byte.

Source

pub fn i8(&mut self) -> Result<i8>

Read a signed byte.

Source

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

Read an unsigned 16-bit word.

Source

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

Read a signed 16-bit word.

Source

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

Read an unsigned word, also usable for exact f32 storage bits.

Source

pub fn i32(&mut self) -> Result<i32>

Read a signed 32-bit word.

Source

pub fn f32(&mut self) -> Result<f32>

Read an IEEE-754 single-precision value.

Source

pub fn count(&mut self, maximum: usize, stride: usize) -> Result<usize>

Read a nonnegative count bounded by both policy and available storage.

Source

pub fn string(&mut self, maximum: usize) -> Result<Vec<u8>>

Read an original length-prefixed byte string.

Source

pub fn end(&self) -> Result<()>

Require exact record consumption.

Auto Trait Implementations§

§

impl<'a> Freeze for Reader<'a>

§

impl<'a> RefUnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>

§

impl<'a> Sync for Reader<'a>

§

impl<'a> Unpin for Reader<'a>

§

impl<'a> UnsafeUnpin for Reader<'a>

§

impl<'a> UnwindSafe for Reader<'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, 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.