xarxa

Crates

git

Versions

default

Flavors

Skip to main content

Pool

Trait Pool 

Source
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 a static. Needs no heap.
  • AllocPool: buffers allocated from the heap, up to a limit. Needs the alloc feature.

To implement it yourself, build buffers with [PacketBuf::from_raw_parts].

Implementations must guarantee:

  • Every buffer alloc returns has a capacity of buf_capacity.
  • buf_capacity is between 128 and 65535, and never changes.

PacketBuf has no lifetime, so the pool must be 'static.

Required Methods§

Source

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.

Source

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".

Implementors§

Source§

impl<const SIZE: usize, const ALIGN: usize> Pool for AllocPool<SIZE, ALIGN>
where Align<ALIGN>: ValidAlign,

Source§

impl<const SIZE: usize, const COUNT: usize, const ALIGN: usize> Pool for StaticPool<SIZE, COUNT, ALIGN>
where Align<ALIGN>: ValidAlign,