Skip to main content

Reader

Trait Reader 

Source
pub trait Reader<'de> {
    // Required method
    fn read_bytes(&mut self, n: usize) -> Result<&'de [u8], Error>;

    // Provided method
    fn read_byte(&mut self) -> Result<u8, Error> { ... }
}
Expand description

Raw byte source that lends buffer-lifetime views. 'de is the lifetime of the underlying buffer. Reads consume forward; there is no rewind, no peek.

Only slice-backed readers (where all the data is already present) can implement this, since read_bytes must return a view that outlives the &mut self borrow.

Required Methods§

Source

fn read_bytes(&mut self, n: usize) -> Result<&'de [u8], Error>

Consume n bytes, returning a zero-copy view tied to the underlying buffer (lifetime 'de). The copy path treats it as a transient slice; the borrow path (&'de str / &'de [u8]) retains it.

Provided Methods§

Source

fn read_byte(&mut self) -> Result<u8, Error>

Consume and return the next byte.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'de> Reader<'de> for SliceReader<'de>