BorrowReader

Struct BorrowReader 

Source
pub struct BorrowReader<'de> { /* private fields */ }
Expand description

Struct used in [storekey::BorrowDecode] 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<'de> BorrowReader<'de>

Source

pub const fn new(slice: &'de [u8]) -> Self

Create a new reader.

Source

pub fn is_empty(&self) -> bool

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_cow(&mut self) -> Result<Cow<'de, [u8]>, DecodeError>

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

If the string encoded in the buffer does not contain escaped characters this function will return a Cow::Borrowed.

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_str_cow(&mut self) -> Result<Cow<'de, str>, DecodeError>

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

If the string encoded in the buffer does not contain escaped characters this function will return a Cow::Borrowed.

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_escaped_slice(&mut self) -> Result<&'de EscapedSlice, DecodeError>

Reads an escaped slice from the reader, expecting the sequence of bytes to be ended by a terminal zero byte.

This function never allocates and always returns a borrowed value.

Calling this function unsets the expected escape flag before returning.

Source

pub fn read_escaped_str(&mut self) -> Result<&'de EscapedStr, DecodeError>

Reads an escaped str from the reader, expecting the sequence of bytes to be ended by a terminal zero byte.

This function never allocates and always returns a borrowed value.

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<'de> Freeze for BorrowReader<'de>

§

impl<'de> RefUnwindSafe for BorrowReader<'de>

§

impl<'de> Send for BorrowReader<'de>

§

impl<'de> Sync for BorrowReader<'de>

§

impl<'de> Unpin for BorrowReader<'de>

§

impl<'de> UnwindSafe for BorrowReader<'de>

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.