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>
impl<'de> BorrowReader<'de>
pub fn is_empty(&self) -> bool
Sourcepub fn expect_escaped(&mut self)
pub fn expect_escaped(&mut self)
Mark the next byte as possibly containing an escaped bytes.
Sourcepub fn read_terminal(&mut self) -> Result<bool, DecodeError>
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.
Sourcepub fn read_array<const SIZE: usize>(
&mut self,
) -> Result<[u8; SIZE], DecodeError>
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.
Sourcepub fn read_cow(&mut self) -> Result<Cow<'de, [u8]>, DecodeError>
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.
Sourcepub fn read_vec(&mut self) -> Result<Vec<u8>, DecodeError>
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.
Sourcepub fn read_str_cow(&mut self) -> Result<Cow<'de, str>, DecodeError>
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.
Sourcepub fn read_string(&mut self) -> Result<String, DecodeError>
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.
Sourcepub fn read_escaped_slice(&mut self) -> Result<&'de EscapedSlice, DecodeError>
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.
Sourcepub fn read_escaped_str(&mut self) -> Result<&'de EscapedStr, DecodeError>
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.