Skip to main content

Reader

Struct Reader 

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

A buffer values are read from.

Implementations§

§

impl<'a> Reader<'a>

pub fn new(data: &'a [u8]) -> Reader<'a>

Reads values from a borrowed buffer without copying it.

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

The bytes not yet read.

pub fn take_bytes(&mut self, len: usize) -> Result<&'a [u8], WireError>

Takes exactly len bytes, refusing a length beyond the remaining buffer.

pub fn take_len(&mut self, min: usize) -> Result<usize, WireError>

A length read before items values of at least min bytes each: refused when the rest of the buffer could not hold them, so no allocation outruns its input.

pub fn take<T>(&mut self) -> Result<T, WireError>
where T: Wire,

Decodes one value from the current position.

pub fn bounded<T>( &mut self, max_bytes: usize, read: impl FnOnce(&mut Reader<'a>) -> Result<T, WireError>, ) -> Result<T, WireError>

Read one value from at most max_bytes, preserving the enclosing reader’s depth and leaving the following value untouched. No nested allocation can outrun this byte window.

pub fn list_with<T>( &mut self, max_items: usize, read: impl FnMut(&mut Reader<'a>) -> Result<T, WireError>, ) -> Result<Vec<T>, WireError>
where T: Wire,

A normal Wire list, with its element cap checked before allocating storage. read may impose a shared payload budget across its elements without a second list codec.

pub fn nested<T>( &mut self, read: impl FnOnce(&mut Reader<'a>) -> Result<T, WireError>, ) -> Result<T, WireError>

Reads one level down: the depth the value may nest to is MAX_DEPTH.

pub fn decode<T>(data: &'a [u8]) -> Result<T, WireError>
where T: Wire,

The whole of data as one T.

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.