Skip to main content

StaticRing

Struct StaticRing 

Source
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>

Source

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).

Source

pub fn push(&self, record: T) -> Result<(), T>

Push one record; Err(record) if full (no blocking). MPMC-safe.

Source

pub fn dequeue(&self) -> Option<T>

Pop one record in FIFO order; None if empty. MPMC-safe.

Source

pub fn len(&self) -> usize

Items currently buffered (snapshot, not linearizable).

Source

pub fn is_empty(&self) -> bool

Source

pub const fn capacity(&self) -> usize

Trait Implementations§

Source§

impl<T, const N: usize> Default for StaticRing<T, N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, const N: usize> Drop for StaticRing<T, N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T, const N: usize> RingStorage for StaticRing<T, N>

Source§

type Item = T

The queued element.
Source§

fn push(&self, item: T) -> Result<(), T>

Push one item; on a full ring the item is handed back via Err.
Source§

fn dequeue(&self) -> Option<T>

Pop the oldest item, or None when empty.
Source§

fn len(&self) -> usize

Snapshot of the number of queued items (not linearizable).
Source§

fn capacity(&self) -> usize

The ring’s capacity (a power of two).
Source§

fn is_empty(&self) -> bool

True when the ring holds nothing (snapshot).
Source§

fn drain_into(&self, out: &mut [Self::Item]) -> usize

Pop up to out.len() items FIFO into out, returning the count filled. Default is a dequeue loop; the heap Ring overrides it with its prefetching batch Drainer.
Source§

impl<T: Send, const N: usize> Send for StaticRing<T, N>

Source§

impl<T: Send, const N: usize> Sync for StaticRing<T, N>

Auto Trait Implementations§

§

impl<T, const N: usize> !Freeze for StaticRing<T, N>

§

impl<T, const N: usize> !RefUnwindSafe for StaticRing<T, N>

§

impl<T, const N: usize> Unpin for StaticRing<T, N>
where [Cell<T>; N]: Unpin,

§

impl<T, const N: usize> UnsafeUnpin for StaticRing<T, N>
where [Cell<T>; N]: UnsafeUnpin,

§

impl<T, const N: usize> UnwindSafe for StaticRing<T, N>
where [Cell<T>; N]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.