Struct Reader

Source
pub struct Reader { /* private fields */ }
Expand description

Panic-free forward-only cursor. See the module level docs.

Implementations§

Source§

impl Reader

Source

pub fn new<T: Into<Bytes>>(bytes: T) -> Self

Creates a new Reader from anything that implements Into<Bytes>.

This does not allocate by itself, but the Into<Bytes> implementation might.

Source

pub fn remaining(&self) -> usize

Returns how many bytes have not been read.

Source

pub fn at_least(&self, len: usize) -> bool

Returns true if at least len many bytes are unread.

Source

pub fn consumed(&self) -> usize

Returns how many bytes have been read so far.

Source

pub fn skip(&mut self, amt: usize)

Skips amt bytes.

Source

pub fn peek(&self, val: u8) -> bool

Returns true if there is another byte to read and it is equal to val.

Source

pub fn read_to_end(self) -> Bytes

Returns the rest of the unread data, consuming the iterator.

Special behavior: If there are no bytes left, the inner value will be dropped, instead returning a Bytes pointing to a static, empty slice.

Source

pub fn subreader(&mut self, len: usize) -> Result<Self, EndOfInput>

Returns a Reader that can read the next len bytes, advancing the original cursor by the same amount.

Source

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

Reads a single byte. Identical to read_u8.

Source

pub fn read_bytes(&mut self, len: usize) -> Result<Bytes, EndOfInput>

Returns the next len bytes as a Bytes, advancing the cursor.

Source

pub fn read_slice(&mut self, len: usize) -> Result<&[u8], EndOfInput>

Returns the next len bytes as a slice, advancing the cursor. The returned slice will always be of length len.

Source

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

Returns an array of size N, advancing the cursor.

Source

pub fn read<T: Decode>(&mut self) -> Result<T, EndOfInput>

Attempts to read a value based on its Decode implementation.

Trait Implementations§

Source§

impl AsMut<Reader> for Reader

Source§

fn as_mut(&mut self) -> &mut Reader

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl From<Bytes> for Reader

Source§

fn from(value: Bytes) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !Freeze for Reader

§

impl RefUnwindSafe for Reader

§

impl Send for Reader

§

impl Sync for Reader

§

impl Unpin for Reader

§

impl UnwindSafe for Reader

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.