serde_cbor::de

Trait Read

Source
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§

Source

fn next(&mut self) -> Result<Option<u8>>

Read the next byte from the input, if any.

Source

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.

Source

fn clear_buffer(&mut self)

Clear the underlying scratch buffer

Source

fn read_to_buffer(&mut self, n: usize) -> Result<()>

Append n bytes from the reader to the reader’s scratch buffer (without clearing it)

Source

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.

Source

fn read_into(&mut self, buf: &mut [u8]) -> Result<()>

Read from the input until buf is full or end of input is encountered.

Source

fn discard(&mut self)

Discard any data read by peek.

Source

fn offset(&self) -> u64

Returns the offset from the start of the reader.

Provided Methods§

Source

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).

Implementors§

Source§

impl<'a> Read<'a> for MutSliceRead<'a>

Source§

impl<'a, 'b> Read<'a> for SliceReadFixed<'a, 'b>