pub struct Consumer<'a, const N: usize> { /* private fields */ }Expand description
A Consumer is a smart pointer to a Buffer, which is endowed with
the right to remove data from the buffer. Only one Consumer may exist
at one time for any given buffer. The methods of a Consumer are the
only way to read data out of a Buffer.
Implementations§
Source§impl<'a, const N: usize> Consumer<'a, N>
impl<'a, const N: usize> Consumer<'a, N>
Sourcepub fn read<'b>(&'b mut self, target_len: usize) -> Region<'b, Self>
pub fn read<'b>(&'b mut self, target_len: usize) -> Region<'b, Self>
Return a Region for up to target_len bytes to be read from
the buffer. The returned region may be shorter than target_len.
The returned region has length zero if and only if the buffer is empty.
The returned region is guaranteed to be not longer than target_len.
To read the largest possible length, set target_len = usize::MAX.
Even though we are reading from the buffer, the Region which is returned
is mutable. Its memory is available for arbitrary use by the caller
for as long as the Region remains in scope.
Sourcepub unsafe fn read_ref<T: Copy + ?Sized>(
&mut self,
item: &mut T,
) -> Result<(), ()>
pub unsafe fn read_ref<T: Copy + ?Sized>( &mut self, item: &mut T, ) -> Result<(), ()>
If the buffer contains enough bytes to make an instance of T, then write
them into *item and return Ok. Otherwise, return Err. UNSAFE: caller
must guarantee that the bytes contained in the buffer constitute a valid
instance of T. In consequence, if T is an integer type or an integer
array or slice type, then it is safe to call this function.