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>
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)>
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
type Error = <A as BufferAlloc<B>>::Error
reuse_or_realloc
.Source§impl<I: ReusableBuffer, O: ReusableBuffer, A: BufferAlloc<O>> BufferProvider<I, Either<I, O>> for MaybeReuseBufferProvider<A>
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)>
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
type Error = <A as BufferAlloc<O>>::Error
reuse_or_realloc
.