pub struct Capped<'a, B: 'a + Buf + ?Sized> { /* private fields */ }Expand description
A soft-limited wrapper for impl Buf that doesn’t invoke extra work whenever the buffer is read
from, only when the remaining bytes are checked. This means it can be nested arbitrarily without
adding extra work every time.
Implementations§
Source§impl<'a, B: 'a + Buf + ?Sized> Capped<'a, B>
impl<'a, B: 'a + Buf + ?Sized> Capped<'a, B>
Sourcepub fn new(buf: &'a mut B) -> Self
pub fn new(buf: &'a mut B) -> Self
Creates a Capped instance with a cap at the very end of the given buffer.
Sourcepub fn new_length_delimited(buf: &'a mut B) -> Result<Self, DecodeError>
pub fn new_length_delimited(buf: &'a mut B) -> Result<Self, DecodeError>
Reads a length from the beginning of the given buffer, then returns a Capped instance with its cap at the end of the delimited range.
pub fn lend(&mut self) -> Capped<'_, B>
Sourcepub fn take_length_delimited(&mut self) -> Result<Capped<'_, B>, DecodeError>
pub fn take_length_delimited(&mut self) -> Result<Capped<'_, B>, DecodeError>
Reads a length delimiter from the beginning of the wrapped buffer, then returns a subsidiary Capped instance for the delineated bytes if it does not overrun the underlying buffer or this instance’s cap.
pub fn buf(&mut self) -> &mut B
pub fn take_all(self) -> Take<&'a mut B>
pub fn decode_varint(&mut self) -> Result<u64, DecodeError>
Sourcepub fn remaining_before_cap(&self) -> usize
pub fn remaining_before_cap(&self) -> usize
Returns the number of bytes left before the cap.
pub fn has_remaining(&self) -> Result<bool, DecodeErrorKind>
Source§impl<'a> Capped<'_, &'a [u8]>
impl<'a> Capped<'_, &'a [u8]>
Sourcepub fn take_borrowed_length_delimited(
&mut self,
) -> Result<&'a [u8], DecodeError>
pub fn take_borrowed_length_delimited( &mut self, ) -> Result<&'a [u8], DecodeError>
Reads a length delimiter from the beginning of the wrapped slice, then advances that inner slice past the delineated bytes and returns them borrowed with lifetime if the instance’s cap is not overrun.