Trait Pool
pub trait Pool: Sync {
// Required methods
fn alloc(&'static self) -> Option<DriverBuf>;
fn has_free(&self, count: usize) -> bool;
fn buf_capacity(&self) -> usize;
}Expand description
Packet pool trait.
You most likely don’t want to implement this trait, instead use one of the ready-made implementations provided by this crate:
StaticPool: a fixed number of buffers, in astatic. Needs no heap.AllocPool: buffers allocated from the heap, up to a limit. Needs theallocfeature.
To implement it yourself, build buffers with [DriverBuf::from_raw].
Implementations must guarantee:
- Every buffer
allocreturns has acapacityofbuf_capacity. - Every buffer
allocreturns has the pool’s own address as its [RawDriverBuf::pool]. buf_capacityis between 128 and 65535, and never changes.
DriverBuf has no lifetime, so the pool must be 'static.
Required Methods§
fn alloc(&'static self) -> Option<DriverBuf>
fn alloc(&'static self) -> Option<DriverBuf>
Allocate a buffer.
Returns None if the pool has no buffer to give.
The buffer has zero headroom and length, and default metadata. Its storage may hold data from earlier packets.
fn has_free(&self, count: usize) -> bool
fn has_free(&self, count: usize) -> bool
Whether at least count buffers are free.
The stack asks before it lets a buffer wait, to keep some free.
fn buf_capacity(&self) -> usize
fn buf_capacity(&self) -> usize
Size of the storage of each buffer, in bytes.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".