Expand description
Fixed-size BufferPool for no_std firmware using embassy_sync.
The pool holds N values of type T (1..=32 slots). A bitmask tracks which
slots are free; BufferGuard and MappedBufferGuard return a slot to the pool on
Drop. When the pool is empty, BufferPool::take registers a waker and completes
when another task releases a buffer.
§Requirements
- Acquire APIs take
&'static self: the pool is intended to live in astaticitem. - Choose a
RawMutex(M) compatible with your executor (for example the critical-section mutex inembassy_sync). - To build the backing
[T; N]in aconstcontext, use[expr; N]when that is valid for your type, orarray_new!when you need distinct elements orTis notCopy(repeat-array syntax requiresCopyin the general case).
§Example
ⓘ
use embedded_buffer_pool::BufferPool;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
/// Shared pool: two 64-byte packet buffers.
static POOL: BufferPool<CriticalSectionRawMutex, [u8; 64], 2> =
BufferPool::new([[0u8; 64]; 2]);
fn try_fill() -> Option<()> {
let mut guard = POOL.try_take()?;
guard[0] = 0xAA;
Some(())
}
async fn wait_for_buffer() {
let mut guard = POOL.take().await;
guard[0] = 0xBB;
}For arrays built by repeating an expression (constructors, const values, literals),
see array_new.
Macros§
- array_
new - Builds
[T; N]by repeating the same expressionNtimes in the source.
Structs§
- Buffer
Guard - Exclusive handle to one pooled
T. Releasing the slot onDrop. - Buffer
Pool - Pool of
Nbuffers of typeT, synchronized with mutexM. - Mapped
Buffer Guard - Like
BufferGuard, but derefs to a borrowedU(often a slice or inner field).