pub trait Pool: Sync {
// Required methods
fn alloc(&'static self) -> Option<PacketBuf>;
fn buf_capacity(&self) -> usize;
}Expand description
Packet pool trait.
You mist 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 [PacketBuf::from_raw_parts].
Implementations must guarantee:
- Every buffer
allocreturns has acapacityofbuf_capacity. buf_capacityis between 128 and 65535, and never changes.
PacketBuf has no lifetime, so the pool must be 'static.
Required Methods§
Sourcefn alloc(&'static self) -> Option<PacketBuf>
fn alloc(&'static self) -> Option<PacketBuf>
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.
Sourcefn 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".