pub struct Queue<T, const N: usize> { /* private fields */ }Expand description
A bounded lock-free multi-producer multi-consumer queue with static storage.
Capacity N is fixed at compile time; the whole queue (including all
slots) lives inline, so Queue::new() is const and the queue can be
placed in a static with no allocator involved (requires the default
build; with loom feature, use Queue::new() at runtime — see below).
push returns Result<(), T> on full push, pop returns Option<T> —
plus Queue::enqueue/Queue::dequeue aliases matching the old
heapless::mpmc API for drop-in migration.
§Static initialization
// Default build: `Queue::new()` is `const`.
static Q: Queue<u32, 8> = Queue::new();With --features loom, new() is a regular function: construct at runtime.
Implementations§
Source§impl<T, const N: usize> Queue<T, N>
impl<T, const N: usize> Queue<T, N>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates an empty queue. const-compatible on the default build:
static Q: Queue<u32, 8> = Queue::new();.
With the loom feature this is a regular (non-const) function
because loom’s atomics are runtime-only; use it at runtime there.
Sourcepub fn push(&self, value: T) -> Result<(), T>
pub fn push(&self, value: T) -> Result<(), T>
Attempts to push. On full queue, returns the value back as Err.
Sourcepub fn enqueue(&self, value: T) -> Result<(), T>
pub fn enqueue(&self, value: T) -> Result<(), T>
Alias of Queue::push matching the heapless::mpmc API.
Sourcepub fn force_push(&self, value: T) -> Option<T>
pub fn force_push(&self, value: T) -> Option<T>
Pushes, replacing the oldest element if full (returns it, else None).
Ring-buffer mode.
Sourcepub fn dequeue(&self) -> Option<T>
pub fn dequeue(&self) -> Option<T>
Alias of Queue::pop matching the heapless::mpmc API.
Sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
true if no push can succeed without Queue::force_push.