pub struct BufferPool { /* private fields */ }Expand description
Pool of reusable BufferChunk allocations for serialisation and framing.
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn with_config(
config: &BufferConfig,
custom_allocator: &Option<Arc<dyn ChunkAllocator>>,
) -> BufferPool
pub fn with_config( config: &BufferConfig, custom_allocator: &Option<Arc<dyn ChunkAllocator>>, ) -> BufferPool
Creates a BufferPool from a BufferConfig and an optional ChunkAllocator
Sourcepub fn get_buffer(&mut self) -> Option<BufferChunk>
pub fn get_buffer(&mut self) -> Option<BufferChunk>
Returns a reusable buffer if one is currently available.
The pool first tries to reclaim an unlocked returned buffer and only allocates a fresh chunk if the configured pool limit still allows it.
Sourcepub fn return_buffer(&mut self, buffer: BufferChunk)
pub fn return_buffer(&mut self, buffer: BufferChunk)
Returns a buffer to the pool after use.
Sourcepub fn drain_returned(&mut self) -> Drain<'_, BufferChunk>
pub fn drain_returned(&mut self) -> Drain<'_, BufferChunk>
Drains all returned buffers from the pool in oldest-to-newest order.
Sourcepub fn get_pool_sizes(&self) -> (usize, usize)
pub fn get_pool_sizes(&self) -> (usize, usize)
Returns the number of allocated buffers and the current number of buffers in the pool Returns the number of allocated buffers and the current number of idle buffers in the pool.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BufferPool
impl !RefUnwindSafe for BufferPool
impl Send for BufferPool
impl !Sync for BufferPool
impl Unpin for BufferPool
impl UnsafeUnpin for BufferPool
impl !UnwindSafe for BufferPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more