pub enum BufferCfg {
SpmcRing {
capacity: usize,
},
SingleLatest,
Mailbox,
}Expand description
Buffer configuration for a record type
Selects buffering strategy: SPMC Ring (backlog), SingleLatest (state sync), or Mailbox (commands).
§Quick Selection Guide
- High-frequency data (>10 Hz):
SpmcRingwith tuned capacity - State/config updates:
SingleLatest(only latest matters) - Commands/one-shot events:
Mailbox
§Examples
use aimdb_core::buffer::BufferCfg;
let telemetry = BufferCfg::SpmcRing { capacity: 2048 }; // High-freq data
let config = BufferCfg::SingleLatest; // State sync
let commands = BufferCfg::Mailbox; // CommandsVariants§
SpmcRing
SPMC (Single Producer, Multiple Consumer) ring buffer
Best for high-frequency data streams with bounded memory. Fast producers can outrun slow consumers (lag detection). Oldest messages dropped on overflow.
Sizing: capacity = data_rate_hz × lag_seconds (use power-of-2).
The Tokio adapter’s broadcast backend rounds capacity up to the next
power of two, so the effective capacity can exceed the configured
value; metrics report the configured capacity.
SingleLatest
Single latest value buffer (no backlog)
Only most recent value is kept. Consumers always get latest state. Intermediate updates are collapsed. Use when history doesn’t matter.
A reader that subscribes after a value has already been produced observes that value once, as if it had been pushed after subscription — a late subscriber to state wants the current state, not just future changes. If nothing has been produced yet, the reader waits. This fresh-subscriber rule is identical across all runtime adapters (tokio, embassy, and wasm) and is enforced by the shared buffer contract suite.
Mailbox
Single-slot mailbox with overwrite
New value overwrites old if not consumed: delivery is at-most-once per value — an unconsumed value is lost on overwrite. Use for commands where the latest command wins.
With multiple subscribers, consumption is competitive: each value is
taken by exactly one subscriber, nondeterministically. Unlike
SpmcRing and SingleLatest, a mailbox does not fan out.