Trait musli_utils::reader::Reader
source · pub trait Reader<'de> {
type Mut<'this>: Reader<'de>
where Self: 'this;
// Required methods
fn borrow_mut(&mut self) -> Self::Mut<'_>;
fn skip<C>(&mut self, cx: &C, n: usize) -> Result<(), C::Error>
where C: ?Sized + Context;
fn peek<C>(&mut self, cx: &C) -> Result<Option<u8>, C::Error>
where C: ?Sized + Context;
fn read_bytes<C, V>(
&mut self,
cx: &C,
n: usize,
visitor: V
) -> Result<V::Ok, C::Error>
where C: ?Sized + Context,
V: ValueVisitor<'de, C, [u8]>;
// Provided methods
fn read<C>(&mut self, cx: &C, buf: &mut [u8]) -> Result<(), C::Error>
where C: ?Sized + Context { ... }
fn read_byte<C>(&mut self, cx: &C) -> Result<u8, C::Error>
where C: ?Sized + Context { ... }
fn read_array<C, const N: usize>(
&mut self,
cx: &C
) -> Result<[u8; N], C::Error>
where C: ?Sized + 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>
fn skip<C>(&mut self, cx: &C, n: usize) -> Result<(), C::Error>
Skip over the given number of bytes.
Provided Methods§
sourcefn read<C>(&mut self, cx: &C, buf: &mut [u8]) -> Result<(), C::Error>
fn read<C>(&mut self, cx: &C, buf: &mut [u8]) -> Result<(), C::Error>
Read a slice into the given buffer.
Object Safety§
This trait is not object safe.