Skip to main content

Crate slotpool

Crate slotpool 

Source
Expand description

Fixed-capacity object pools for no_std / embedded systems.

Two pool variants, sharing the same pluggable-backend architecture:

VariantAllocateDropUse case
BoxPoolalloc(value) — writes a new valueruns T’s destructorowned objects
ObjectPoolrequest() — no value, previous data persistsno destructorbuffers, messages
  • Static memory, no heap allocation.
  • Safe sharing between ISRs and async tasks.
  • Pluggable backends via generic B; default is CriticalSlots. Enable feature = "cas" for CasSlots.

§BoxPool — owned values

use slotpool::{BoxPool, StaticBoxPool};

static POOL: StaticBoxPool<[u8; 256], 8> = StaticBoxPool::new();
let pool: &'static BoxPool<[u8; 256], 8> = POOL.init_pool();

let guard = pool.alloc([0u8; 256]).unwrap();
// guard is returned to the pool when dropped; destructor runs

§ObjectPool — persistent buffers / messages

use slotpool::{ObjectPool, StaticObjectPool};

static POOL: StaticObjectPool<[u8; 256], 8> = StaticObjectPool::new();
let pool: &'static ObjectPool<[u8; 256], 8> = POOL.init_pool([0u8; 256]);

let mut buf = pool.request().unwrap();
buf[0..4].copy_from_slice(&header);
// buf is returned to the pool when dropped; no destructor — data persists

§Backend selection

use slotpool::critical::CriticalSlots;
#[cfg(feature = "cas")]
use slotpool::cas::CasSlots;

type MyPool    = StaticBoxPool<[u8; 256], 8>;                    // default: CriticalSlots
type MyCasPool = StaticBoxPool<[u8; 256], 8, CasSlots<8>>;      // CAS backend

The free-index chain is stored separately from T’s slots — this is not an intrusive free list, so slot memory layout is unaffected.

Modules§

critical
Critical-section backend: a heapless::Vec protected by critical_section::Mutex.

Structs§

BoxGuard
A handle to an allocated BoxPool slot. Derefs to &mut T; returns the slot to the pool and runs T’s destructor on drop.
BoxPool
Owned-value pool — like heapless::BoxPool.
ObjectGuard
A borrow of an ObjectPool slot. Derefs to &mut T; returns the slot to the pool on drop without running T’s destructor — the data persists for the next request().
ObjectPool
Persistent-object pool — like heapless::ObjectPool.
StaticBoxPool
Static storage for a BoxPool — the only way to create one.
StaticObjectPool
Static storage for an ObjectPool — the only way to create one.