Expand description
Fixed-capacity object pools for no_std / embedded systems.
Two pool variants, sharing the same pluggable-backend architecture:
| Variant | Allocate | Drop | Use case |
|---|---|---|---|
BoxPool | alloc(value) — writes a new value | runs T’s destructor | owned objects |
ObjectPool | request() — no value, previous data persists | no destructor | buffers, messages |
- Static memory, no heap allocation.
- Safe sharing between ISRs and async tasks.
- Pluggable backends via generic
B; default isCriticalSlots. Enablefeature = "cas"forCasSlots.
§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 backendThe 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::Vecprotected bycritical_section::Mutex.
Structs§
- BoxGuard
- A handle to an allocated
BoxPoolslot. Derefs to&mut T; returns the slot to the pool and runsT’s destructor on drop. - BoxPool
- Owned-value pool — like
heapless::BoxPool. - Object
Guard - A borrow of an
ObjectPoolslot. Derefs to&mut T; returns the slot to the pool on drop without runningT’s destructor — the data persists for the nextrequest(). - Object
Pool - Persistent-object pool — like
heapless::ObjectPool. - Static
BoxPool - Static storage for a
BoxPool— the only way to create one. - Static
Object Pool - Static storage for an
ObjectPool— the only way to create one.