1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! 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 is [`CriticalSlots`](critical::CriticalSlots).
//! Enable `feature = "cas"` for [`CasSlots`](cas::CasSlots).
//!
//! ## BoxPool — owned values
//!
//! ```ignore
//! 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
//!
//! ```ignore
//! 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
//!
//! ```ignore
//! 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.
pub use ;
pub use ;