Reader

Struct Reader 

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

Struct used in [storekey::Decode] for reading types from the buffer.

This type handles unescaping bytes the buffer mostly transparently. It has an internal flag for marking when an escaped byte can be read from the buffer. Reading from the buffer in any way unmarks this flag.

Implementations§

Source§

impl<R: BufRead> Reader<R>

Source

pub const fn new(r: R) -> Self

Create a new reader.

Source

pub fn is_empty(&mut self) -> Result<bool, DecodeError>

Returns if the reader is empty / contains no more data.

Source

pub fn expect_escaped(&mut self)

Mark the next byte as possibly containing an escaped bytes.

Source

pub fn read_terminal(&mut self) -> Result<bool, DecodeError>

Try to read a terminator byte if there is one.

Returns true if the next byte is a terminator, otherwise returns false and the reader does not advance.

Sets the expect_escaped flag marking the next byte as being possibly escaped.

Source

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

Reads an fixed size array of u8 from the reader, unescaping possible escaped bytes.

All other read_* functions of Reader which read a fixed size type call this function to read a certain amount of bytes from the reader.

This type does not expect a null terminator after the end of the array as it is reading a fixed size type.

Calling this function unsets the expected escape flag before returning.

Source

pub fn read_vec(&mut self) -> Result<Vec<u8>, DecodeError>

Reads a runtime sized Vec<u8> from the reader, expected the sequence of bytes to be ended by a terminal zero byte.

Calling this function unsets the expected escape flag before returning.

Source

pub fn read_string(&mut self) -> Result<String, DecodeError>

Reads a runtime sized String from the reader, expected the sequence of bytes to be ended by a terminal zero byte.

Calling this function unsets the expected escape flag before returning.

Source

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

Source

pub fn read_f64(&mut self) -> Result<f64, DecodeError>

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn read_i64(&mut self) -> Result<i64, DecodeError>

Source

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

Source

pub fn read_i128(&mut self) -> Result<i128, DecodeError>

Source

pub fn read_u128(&mut self) -> Result<u128, DecodeError>

Auto Trait Implementations§

§

impl<R> Freeze for Reader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Reader<R>
where R: RefUnwindSafe,

§

impl<R> Send for Reader<R>
where R: Send,

§

impl<R> Sync for Reader<R>
where R: Sync,

§

impl<R> Unpin for Reader<R>
where R: Unpin,

§

impl<R> UnwindSafe for Reader<R>
where R: UnwindSafe,

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.