embassy-net

Crates

git

Versions

default

Flavors

Skip to main content

Pool

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 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 [DriverBuf::from_raw].

Implementations must guarantee:

  • Every buffer alloc returns has a capacity of buf_capacity.
  • Every buffer alloc returns has the pool’s own address as its [RawDriverBuf::pool].
  • buf_capacity is 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>

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

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

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§

§

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