pub trait Reader<'de>: Sealed {
type Mut<'this>: Reader<'de>
where Self: 'this;
type TryClone: Reader<'de>;
// Required methods
fn borrow_mut(&mut self) -> Self::Mut<'_>;
fn try_clone(&self) -> Option<Self::TryClone>;
fn is_eof(&mut self) -> bool;
fn skip<C>(&mut self, cx: C, n: usize) -> Result<(), C::Error>
where C: Context;
fn peek(&mut self) -> Option<u8>;
fn read_bytes<C, V>(
&mut self,
cx: C,
n: usize,
visitor: V,
) -> Result<V::Ok, V::Error>
where C: Context,
V: UnsizedVisitor<'de, C, [u8], Error = C::Error, Allocator = C::Allocator>;
unsafe fn read_bytes_uninit<C>(
&mut self,
cx: C,
ptr: *mut u8,
len: usize,
) -> Result<(), C::Error>
where C: Context;
// Provided methods
fn read<C>(&mut self, cx: C, buf: &mut [u8]) -> Result<(), C::Error>
where C: Context { ... }
fn read_byte<C>(&mut self, cx: C) -> Result<u8, C::Error>
where C: Context { ... }
fn read_array<C, const N: usize>(
&mut self,
cx: C,
) -> Result<[u8; N], C::Error>
where C: Context { ... }
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>
where
Self: 'this
type Mut<'this>: Reader<'de> 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: C, n: usize) -> Result<(), C::Error>where
C: Context,
fn skip<C>(&mut self, cx: C, n: usize) -> Result<(), C::Error>where
C: Context,
Skip over the given number of bytes.
Provided Methods§
Sourcefn read<C>(&mut self, cx: C, buf: &mut [u8]) -> Result<(), C::Error>where
C: Context,
fn read<C>(&mut self, cx: C, buf: &mut [u8]) -> Result<(), C::Error>where
C: Context,
Read a slice into the given buffer.
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.