packet::serialize

Struct MaybeReuseBufferProvider

Source
pub struct MaybeReuseBufferProvider<A>(pub A);
Expand description

Provides an implementation of BufferProvider from a BufferAlloc A that attempts to reuse the input buffer and falls back to the allocator if the input buffer can’t be reused.

Tuple Fields§

§0: A

Trait Implementations§

Source§

impl<B: ReusableBuffer, A: BufferAlloc<B>> BufferProvider<B, B> for MaybeReuseBufferProvider<A>

Source§

fn reuse_or_realloc( self, buffer: B, prefix: usize, suffix: usize, ) -> Result<B, (A::Error, B)>

If buffer has enough capacity to store need_prefix + need_suffix + buffer.len() bytes, then reuse buffer. Otherwise, allocate a new buffer using A’s BufferAlloc implementation.

If there is enough capacity, but the body is too far forwards or backwards in the buffer to satisfy the prefix and suffix constraints, the body will be moved within the buffer in order to satisfy the constraints. This operation is linear in the length of the body.

Source§

type Error = <A as BufferAlloc<B>>::Error

The type of errors returned from reuse_or_realloc.
Source§

fn alloc_no_reuse( self, prefix: usize, body: usize, suffix: usize, ) -> Result<B, Self::Error>

Attempts to produce an output buffer with the given constraints by allocating a new one. Read more
Source§

impl<I: ReusableBuffer, O: ReusableBuffer, A: BufferAlloc<O>> BufferProvider<I, Either<I, O>> for MaybeReuseBufferProvider<A>

Source§

fn reuse_or_realloc( self, buffer: I, need_prefix: usize, need_suffix: usize, ) -> Result<Either<I, O>, (A::Error, I)>

If buffer has enough capacity to store need_prefix + need_suffix + buffer.len() bytes, then reuse buffer. Otherwise, allocate a new buffer using A’s BufferAlloc implementation.

If there is enough capacity, but the body is too far forwards or backwards in the buffer to satisfy the prefix and suffix constraints, the body will be moved within the buffer in order to satisfy the constraints. This operation is linear in the length of the body.

Source§

type Error = <A as BufferAlloc<O>>::Error

The type of errors returned from reuse_or_realloc.
Source§

fn alloc_no_reuse( self, prefix: usize, body: usize, suffix: usize, ) -> Result<Either<I, O>, Self::Error>

Attempts to produce an output buffer with the given constraints by allocating a new one. Read more

Auto Trait Implementations§

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