Trait Reader

Source
pub trait Reader<'de> {
    type Error: Error;

    // Required methods
    fn skip(&mut self, n: usize) -> Result<(), Self::Error>;
    fn read_bytes<V>(&mut self, n: usize, visitor: V) -> Result<V::Ok, V::Error>
       where V: ValueVisitor<'de, Target = [u8], Error = Self::Error>;

    // Provided methods
    fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> { ... }
    fn read_byte(&mut self) -> Result<u8, Self::Error> { ... }
    fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Self::Error> { ... }
    fn with_position(self) -> WithPosition<Self>
       where Self: Sized { ... }
    fn limit(self, limit: usize) -> Limit<Self>
       where Self: Sized { ... }
}
Expand description

Trait governing how a source of bytes is read.

This requires the reader to be able to hand out contiguous references to the byte source through Reader::read_bytes.

Required Associated Types§

Source

type Error: Error

Error type raised by the current reader.

Required Methods§

Source

fn skip(&mut self, n: usize) -> Result<(), Self::Error>

Skip over the given number of bytes.

Source

fn read_bytes<V>(&mut self, n: usize, visitor: V) -> Result<V::Ok, V::Error>
where V: ValueVisitor<'de, Target = [u8], Error = Self::Error>,

Read a slice out of the current reader.

Provided Methods§

Source

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

Read a slice into the given buffer.

Source

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

Read a single byte.

Source

fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Self::Error>

Read an array out of the current reader.

Source

fn with_position(self) -> WithPosition<Self>
where Self: Sized,

Keep an accurate record of the position within the reader.

Source

fn limit(self, limit: usize) -> Limit<Self>
where Self: Sized,

Keep an accurate record of the position within the reader.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'de> Reader<'de> for &'de [u8]

Source§

type Error = SliceReaderError

Source§

fn skip(&mut self, n: usize) -> Result<(), Self::Error>

Source§

fn read_bytes<V>(&mut self, n: usize, visitor: V) -> Result<V::Ok, V::Error>
where V: ValueVisitor<'de, Target = [u8], Error = Self::Error>,

Source§

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

Source§

impl<'de, R> Reader<'de> for &mut R
where R: ?Sized + Reader<'de>,

Source§

type Error = <R as Reader<'de>>::Error

Source§

fn skip(&mut self, n: usize) -> Result<(), Self::Error>

Source§

fn read_bytes<V>(&mut self, n: usize, visitor: V) -> Result<V::Ok, V::Error>
where V: ValueVisitor<'de, Target = [u8], Error = Self::Error>,

Source§

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

Source§

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

Source§

fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Self::Error>

Implementors§

Source§

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

Source§

impl<'de, R> Reader<'de> for Limit<R>
where R: Reader<'de>,

Source§

type Error = <R as Reader<'de>>::Error

Source§

impl<'de, R> Reader<'de> for WithPosition<R>
where R: Reader<'de>,

Source§

type Error = <R as Reader<'de>>::Error