Skip to main content

Reader

Struct Reader 

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

A cursor over a byte slice with checked little-endian reads.

Implementations§

Source§

impl<'a> Reader<'a>

Source

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

A reader that reports truncation as Check::DirChunkExtent.

Callers parsing a specific structure should prefer Reader::checked.

Source

pub fn checked(buf: &'a [u8], check: Check) -> Self

A reader whose truncation errors report check.

Source

pub fn with_check(self, check: Check) -> Self

The same reader with a different truncation check.

Source

pub fn check(&self) -> Check

The check reported when a read runs past the end.

Source

pub fn pos(&self) -> usize

Bytes consumed so far.

Source

pub fn remaining(&self) -> usize

Bytes left.

Source

pub fn is_empty(&self) -> bool

Whether the reader is exhausted.

Source

pub fn buffer(&self) -> &'a [u8] ⓘ

The whole underlying buffer.

Source

pub fn tail(&self) -> &'a [u8] ⓘ

The not-yet-consumed tail.

Source

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

Read one byte.

Source

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

Read a u16.

Source

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

Read a u32.

Source

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

Read a u64.

Source

pub fn array<const N: usize>(&mut self) -> Result<[u8; N]>

Read a fixed-size array.

Source

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

Borrow the next n bytes.

Source

pub fn rest(&mut self) -> &'a [u8] ⓘ

Borrow the whole tail.

Source

pub fn skip(&mut self, n: usize) -> Result<()>

Skip n bytes.

Source

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

Read a varint (section 5.2).

Source

pub fn varint_bounded(&mut self, max: u64) -> Result<u64>

Read a varint bounded by max, rejecting a value above it before allocation.

Source

pub fn utf8(&mut self, n: usize) -> Result<&'a str>

Read a UTF-8 string of n bytes.

Trait Implementations§

Source§

impl<'a> Clone for Reader<'a>

Source§

fn clone(&self) -> Reader<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Reader<'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 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V