pub struct HeapBufferPool(/* private fields */);Expand description
A bounded, shareable collection of stable initialized slots in one contiguous slab. Construction reserves all payload storage; acquiring, freezing, slicing, and returning leases allocate no payload or reference-count wrappers.
Pools may be shared across connections and file pipelines. Exhaustion waits with cancellation instead of growing the pool. Retained views count against capacity. This portable implementation of BufferPool uses a heap allocation. Backends may supply another pool implementation with the same ownership contract.
Implementations§
Source§impl HeapBufferPool
impl HeapBufferPool
Sourcepub fn new(buffers: usize, buffer_size: usize) -> Result<Self>
pub fn new(buffers: usize, buffer_size: usize) -> Result<Self>
Reserve buffers slots of buffer_size bytes each, with an alignment of 1. This is with_options applied to BufferPoolOptions::new.
Sourcepub fn with_options(options: BufferPoolOptions) -> Result<Self>
pub fn with_options(options: BufferPoolOptions) -> Result<Self>
Reserve one contiguous initialized allocation. Slot starts satisfy the requested alignment; padding is outside the usable payload budget.
Returns io::ErrorKind::InvalidInput if buffers or buffer_size is zero, the alignment is not a power of two, or the total allocation is not representable.
Sourcepub fn buffer_size(&self) -> usize
pub fn buffer_size(&self) -> usize
The usable length, in bytes, of each slot.
Sourcepub fn alignment(&self) -> usize
pub fn alignment(&self) -> usize
The requested minimum alignment, in bytes, of each slot’s first byte.
Sourcepub fn try_acquire(&self) -> Option<BufferLease>
pub fn try_acquire(&self) -> Option<BufferLease>
Acquire exclusive writable storage immediately, or return None without allocating.
Sourcepub async fn acquire(
&self,
cancellation: &Cancellation,
) -> Result<BufferLease, Cancelled>
pub async fn acquire( &self, cancellation: &Cancellation, ) -> Result<BufferLease, Cancelled>
Wait for one lease. Pre-cancellation leaves capacity unchanged; a successfully acquired lease wins a later cancellation race.
Trait Implementations§
Source§impl BufferPool for HeapBufferPool
impl BufferPool for HeapBufferPool
Source§type Buffer = BufferLease
type Buffer = BufferLease
Source§fn capacity(&self) -> usize
fn capacity(&self) -> usize
Source§fn buffer_size(&self) -> usize
fn buffer_size(&self) -> usize
Source§fn alignment(&self) -> usize
fn alignment(&self) -> usize
Source§fn try_acquire(&self) -> Option<Self::Buffer>
fn try_acquire(&self) -> Option<Self::Buffer>
None without waiting for capacity.