Skip to main content

Capped

Struct Capped 

Source
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>

Source

pub fn new(buf: &'a mut B) -> Self

Creates a Capped instance with a cap at the very end of the given buffer.

Source

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.

Source

pub fn lend(&mut self) -> Capped<'_, B>

Source

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.

Source

pub fn buf(&mut self) -> &mut B

Source

pub fn take_all(self) -> Take<&'a mut B>

Source

pub fn decode_varint(&mut self) -> Result<u64, DecodeError>

Source

pub fn remaining_before_cap(&self) -> usize

Returns the number of bytes left before the cap.

Source

pub fn has_remaining(&self) -> Result<bool, DecodeErrorKind>

Source§

impl<'a> Capped<'_, &'a [u8]>

Source

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.

Trait Implementations§

Source§

impl<B: Buf + ?Sized> Deref for Capped<'_, B>

Source§

type Target = B

The resulting type after dereferencing.
Source§

fn deref(&self) -> &B

Dereferences the value.
Source§

impl<B: Buf + ?Sized> DerefMut for Capped<'_, B>

Source§

fn deref_mut(&mut self) -> &mut B

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'a, B> Freeze for Capped<'a, B>
where B: ?Sized,

§

impl<'a, B> RefUnwindSafe for Capped<'a, B>
where B: RefUnwindSafe + ?Sized,

§

impl<'a, B> Send for Capped<'a, B>
where B: Send + ?Sized,

§

impl<'a, B> Sync for Capped<'a, B>
where B: Sync + ?Sized,

§

impl<'a, B> Unpin for Capped<'a, B>
where B: ?Sized,

§

impl<'a, B> UnsafeUnpin for Capped<'a, B>
where B: ?Sized,

§

impl<'a, B> !UnwindSafe for Capped<'a, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.