pub struct StaticRing<T, const N: usize> { /* private fields */ }Expand description
No-alloc, const-capacity bounded ring with lock-free MPMC access — the
bare-metal tier of Ring. The [Cell<T>; N] buffer lives inline (no
heap), so it compiles and runs where alloc is unavailable
(DPDK/SPDK/embedded). Same Vyukov algorithm as Ring — both delegate to the
shared cells_* fns, so loom’s model-check of that algorithm covers this too.
N MUST be a power of two >= 2 (asserted in StaticRing::new); the
protocol needs it for the pos & (N - 1) slot index.
new is const, so the whole no-alloc tier can back a
static on bare metal with no heap and no lazy OnceCell/runtime init:
static RING: StaticRing<T, N> = StaticRing::new();.
StaticBoundedQueue and the pipe-forms
StaticSinkFront inherit that through here.
Implementations§
Source§impl<T, const N: usize> StaticRing<T, N>
impl<T, const N: usize> StaticRing<T, N>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Construct an empty ring, seeding each cell’s sequence to its own index
(the Vyukov empty-slot test is seq == pos, slot by slot). const, so a
bare-metal caller can put one straight in a static; a non-power-of-two
N then fails the BUILD rather than the first call.
loom’s atomics register with the model checker on construction and are
therefore not const-constructible, so the --features loom build gets
the same body without const (same cfg split as write_cell above).
Sourcepub fn push(&self, record: T) -> Result<(), T>
pub fn push(&self, record: T) -> Result<(), T>
Push one record; Err(record) if full (no blocking). MPMC-safe.