pub trait Reader<'de> {
type Error;
type Mut<'this>: Reader<'de, Error = Self::Error>
where Self: 'this;
// Required methods
fn borrow_mut(&mut self) -> Self::Mut<'_>;
fn skip<C>(
&mut self,
cx: &mut C,
n: usize,
) -> Result<(), <C as Context>::Error>
where C: Context<Input = Self::Error>;
fn peek<C>(
&mut self,
cx: &mut C,
) -> Result<Option<u8>, <C as Context>::Error>
where C: Context<Input = Self::Error>;
fn read_bytes<C, V>(
&mut self,
cx: &mut C,
n: usize,
visitor: V,
) -> Result<<V as ValueVisitor<'de, C, [u8]>>::Ok, <C as Context>::Error>
where C: Context,
<C as Context>::Input: From<Self::Error>,
V: ValueVisitor<'de, C, [u8]>;
// Provided methods
fn read<C>(
&mut self,
cx: &mut C,
buf: &mut [u8],
) -> Result<(), <C as Context>::Error>
where C: Context<Input = Self::Error> { ... }
fn read_byte<C>(&mut self, cx: &mut C) -> Result<u8, <C as Context>::Error>
where C: Context<Input = Self::Error> { ... }
fn read_array<C, const N: usize>(
&mut self,
cx: &mut C,
) -> Result<[u8; N], <C as Context>::Error>
where C: Context<Input = Self::Error> { ... }
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§
Sourcetype Mut<'this>: Reader<'de, Error = Self::Error>
where
Self: 'this
type Mut<'this>: Reader<'de, Error = Self::Error> where Self: 'this
Type borrowed from self.
Why oh why would we want to do this over having a simple &'this mut T?
We want to avoid recursive types, which will blow up the compiler. And
the above is a typical example of when that can go wrong. This ensures
that each call to borrow_mut dereferences the Reader at each step to
avoid constructing a large muted type, like &mut &mut &mut SliceReader<'de>.
Required Methods§
Sourcefn borrow_mut(&mut self) -> Self::Mut<'_>
fn borrow_mut(&mut self) -> Self::Mut<'_>
Borrow the current reader.
Sourcefn skip<C>(&mut self, cx: &mut C, n: usize) -> Result<(), <C as Context>::Error>
fn skip<C>(&mut self, cx: &mut C, n: usize) -> Result<(), <C as Context>::Error>
Skip over the given number of bytes.
Provided Methods§
Sourcefn read<C>(
&mut self,
cx: &mut C,
buf: &mut [u8],
) -> Result<(), <C as Context>::Error>
fn read<C>( &mut self, cx: &mut C, buf: &mut [u8], ) -> Result<(), <C as Context>::Error>
Read a slice into the given buffer.
Sourcefn read_byte<C>(&mut self, cx: &mut C) -> Result<u8, <C as Context>::Error>
fn read_byte<C>(&mut self, cx: &mut C) -> Result<u8, <C as Context>::Error>
Read a single byte.
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.