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.

§

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.

§

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

§

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

§

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.