pub trait BytesLike<'bytes>: Sized + Debug {
type Error: Copy + Debug;
type ExternallyTrackedLength: Copy + Debug;
// Required methods
fn len(&self, len: Self::ExternallyTrackedLength) -> usize;
fn peek(&self, i: usize) -> Result<u8, Self::Error>;
fn read_bytes(
&mut self,
bytes: usize,
) -> Result<(Self::ExternallyTrackedLength, Self), Self::Error>;
fn read_into_slice(&mut self, slice: &mut [u8]) -> Result<(), Self::Error>;
// Provided methods
fn read_byte(&mut self) -> Result<u8, Self::Error> { ... }
fn advance(&mut self, bytes: usize) -> Result<(), Self::Error> { ... }
}
Expand description
An item which is like a &[u8]
.
This should be a reference to a buffer for which references are cheap to work with.
Required Associated Types§
Sourcetype ExternallyTrackedLength: Copy + Debug
type ExternallyTrackedLength: Copy + Debug
The type representing the length of a read BytesLike
, if a BytesLike
does not
inherently know its length.
This should be usize
or ()
.
Required Methods§
Sourcefn len(&self, len: Self::ExternallyTrackedLength) -> usize
fn len(&self, len: Self::ExternallyTrackedLength) -> usize
The length of these bytes.
Sourcefn read_bytes(
&mut self,
bytes: usize,
) -> Result<(Self::ExternallyTrackedLength, Self), Self::Error>
fn read_bytes( &mut self, bytes: usize, ) -> Result<(Self::ExternallyTrackedLength, Self), Self::Error>
Read a fixed amount of bytes from the container.
This MUST return Ok((len, slice))
where slice
is the expected length or Err(_)
.
Provided Methods§
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.