Skip to main content

Reader

Struct Reader 

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

Reads values from the start of a slice, in a context, and keeps why one couldn’t be.

Implementations§

Source§

impl<'a> Reader<'a>

Source

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

Source

pub fn with_context(self, context: &'a mut (dyn Context + 'a)) -> Self

This reader, reading in context.

Source

pub fn context<T: Any>(&mut self) -> Option<&T>

The context’s part of type T, if it has one.

Source

pub fn context_mut<T: Any>(&mut self) -> Option<&mut T>

The context’s part of type T, to change, if it has one.

Source

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

The bytes not read yet.

Source

pub fn fail<T>(&mut self, message: &'static str) -> Option<T>

Records why a value can’t be read, and returns None for the read to return.

Source

pub fn error(&self) -> Error

Why a read returned None.

Source

pub fn byte(&mut self) -> Option<u8>

Source

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

The next n bytes.

Source

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

A varint.

Source

pub fn tag(&mut self) -> Option<u32>

An enum’s variant index.

Source

pub fn fail_tag<T>(&mut self) -> Option<T>

Records an enum variant index the enum doesn’t have.

Source

pub fn length(&mut self) -> Option<usize>

A sequence’s length.

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<'a> !UnwindSafe for Reader<'a>

§

impl<'a> Forget for Reader<'a>

§

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

§

impl<'a> Move for Reader<'a>

§

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

§

impl<'a> UnsafeUnpin 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 = !

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.