pub trait Read<'de> {
// Required methods
fn next(&mut self) -> Result<Option<u8>>;
fn peek(&mut self) -> Result<Option<u8>>;
fn clear_buffer(&mut self);
fn read_to_buffer(&mut self, n: usize) -> Result<()>;
fn take_buffer<'a>(&'a mut self) -> EitherLifetime<'a, 'de>;
fn read_into(&mut self, buf: &mut [u8]) -> Result<()>;
fn discard(&mut self);
fn offset(&self) -> u64;
// Provided method
fn read<'a>(&'a mut self, n: usize) -> Result<EitherLifetime<'a, 'de>> { ... }
}
Expand description
Trait used by the deserializer for iterating over input.
Required Methods§
Sourcefn peek(&mut self) -> Result<Option<u8>>
fn peek(&mut self) -> Result<Option<u8>>
Peek at the next byte of the input, if any. This does not advance the reader, so the result of this function will remain the same until a read or clear occurs.
Sourcefn clear_buffer(&mut self)
fn clear_buffer(&mut self)
Clear the underlying scratch buffer
Sourcefn read_to_buffer(&mut self, n: usize) -> Result<()>
fn read_to_buffer(&mut self, n: usize) -> Result<()>
Append n bytes from the reader to the reader’s scratch buffer (without clearing it)
Sourcefn take_buffer<'a>(&'a mut self) -> EitherLifetime<'a, 'de>
fn take_buffer<'a>(&'a mut self) -> EitherLifetime<'a, 'de>
Read out everything accumulated in the reader’s scratch buffer. This may, as a side effect, clear it.
Provided Methods§
Sourcefn read<'a>(&'a mut self, n: usize) -> Result<EitherLifetime<'a, 'de>>
fn read<'a>(&'a mut self, n: usize) -> Result<EitherLifetime<'a, 'de>>
Read n bytes from the input.
Implementations that can are asked to return a slice with a Long lifetime that outlives the decoder, but others (eg. ones that need to allocate the data into a temporary buffer) can return it with a Short lifetime that just lives for the time of read’s mutable borrow of the reader.
This may, as a side effect, clear the reader’s scratch buffer (as the provided implementation does).