pub struct BoundedQueue<R: RingStorage> { /* private fields */ }Expand description
A bounded queue applying a FailMode on overflow, over any RingStorage.
Construct it through a tier alias: StaticBoundedQueue (no-alloc) or
HeapBoundedQueue (alloc).
Implementations§
Source§impl<R: RingStorage> BoundedQueue<R>
impl<R: RingStorage> BoundedQueue<R>
Sourcepub const fn from_storage(queue: R, fail_mode: FailMode) -> Self
pub const fn from_storage(queue: R, fail_mode: FailMode) -> Self
Wrap an already-constructed storage with an overflow policy.
pub fn capacity(&self) -> usize
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn note_drop(&self)
pub fn note_drop(&self)
Count one externally-decided drop. For a caller that applies its OWN
overflow routing on top of try_enqueue (a dynamic
per-item policy the fixed FailMode can’t express) and discards the
handed-back item itself — this folds that drop into the same counter
dropped reports, so the queue stays the single drop
total.
Sourcepub fn enqueue(&self, item: R::Item) -> EnqueueOutcome
pub fn enqueue(&self, item: R::Item) -> EnqueueOutcome
Enqueue under the configured FailMode, counting any drop.
Sourcepub fn try_enqueue(&self, item: R::Item) -> Result<(), R::Item>
pub fn try_enqueue(&self, item: R::Item) -> Result<(), R::Item>
Enqueue WITHOUT the fail policy: on a full ring the item is handed back
via Err so a lossless producer-assist loop can make room and retry it
rather than dropping it. Nothing is counted as dropped. #[inline] — this
is an emit hot path (the telemetry recorder pushes through it per record),
so it must collapse to the bare storage push.
Sourcepub fn enqueue_assisting<F>(
&self,
item: R::Item,
on_full: F,
) -> Result<(), R::Item>
pub fn enqueue_assisting<F>( &self, item: R::Item, on_full: F, ) -> Result<(), R::Item>
Enqueue, looping through a make-room step on a full ring until the item
lands. on_full is the producer’s make-room action (e.g. drain + export a
batch to free a slot); it returns true to keep trying, false to give
up — in which case the un-enqueued item is handed back via Err. This is
the shared producer-assist loop: a strictly-lossless caller passes an
on_full that never gives up (and yields on a no-progress round); a
bounded caller gives up and applies its own overflow policy to the Err.
The loop itself neither counts nor blocks — any yield/park lives in
on_full, so this stays no_std.
Sourcepub fn drain_into(&self, out: &mut [R::Item]) -> usize
pub fn drain_into(&self, out: &mut [R::Item]) -> usize
Batch-pop up to out.len() items FIFO, returning the count filled. Uses
the storage’s batch drain (the heap Ring’s prefetching Drainer).
Source§impl<T, const N: usize> BoundedQueue<StaticRing<T, N>>
impl<T, const N: usize> BoundedQueue<StaticRing<T, N>>
Sourcepub const fn new(fail_mode: FailMode) -> Self
pub const fn new(fail_mode: FailMode) -> Self
A no-alloc bounded queue of capacity N (a power of two ≥ 2 — the
StaticRing requirement). const, so the whole sink stack can live in
a static on bare metal (see StaticRing::new); the loom build drops
the const because loom’s atomics are not const-constructible.