Skip to main content

RingStorage

Trait RingStorage 

Source
pub trait RingStorage {
    type Item;

    // Required methods
    fn push(&self, item: Self::Item) -> Result<(), Self::Item>;
    fn dequeue(&self) -> Option<Self::Item>;
    fn len(&self) -> usize;
    fn capacity(&self) -> usize;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn drain_into(&self, out: &mut [Self::Item]) -> usize { ... }
}
Expand description

The storage a BoundedQueue drives: a lock-free MPMC ring, in either the inline StaticRing (no-alloc) or heap Ring (alloc) form. push hands the item back on a full ring (never blocks); dequeue pops FIFO. The item type is associated so a BoundedQueue<R> names a single storage rather than threading a redundant element parameter.

Required Associated Types§

Source

type Item

The queued element.

Required Methods§

Source

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

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

Source

fn dequeue(&self) -> Option<Self::Item>

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

Provided Methods§

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

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

Source§

type Item = T

Source§

impl<T> RingStorage for Ring<T>

Available on crate feature alloc only.
Source§

type Item = T