Skip to main content

BoundedQueue

Struct BoundedQueue 

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

Source

pub const fn from_storage(queue: R, fail_mode: FailMode) -> Self

Wrap an already-constructed storage with an overflow policy.

Source

pub fn capacity(&self) -> usize

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn dropped(&self) -> u64

Total items dropped or refused on overflow since construction.

Source

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.

Source

pub fn enqueue(&self, item: R::Item) -> EnqueueOutcome

Enqueue under the configured FailMode, counting any drop.

Source

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.

Source

pub fn enqueue_assisting<F>( &self, item: R::Item, on_full: F, ) -> Result<(), R::Item>
where F: FnMut() -> bool,

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.

Source

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

Pop the oldest queued item, if any.

Source

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

Source

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.

Source§

impl<T> BoundedQueue<Ring<T>>

Source

pub fn new(capacity: usize, fail_mode: FailMode) -> Self

A heap-backed bounded queue holding at most capacity items (rounded up to a power of two, minimum 2).

Auto Trait Implementations§

§

impl<R> !Freeze for BoundedQueue<R>

§

impl<R> RefUnwindSafe for BoundedQueue<R>
where R: RefUnwindSafe,

§

impl<R> Send for BoundedQueue<R>
where R: Send,

§

impl<R> Sync for BoundedQueue<R>
where R: Sync,

§

impl<R> Unpin for BoundedQueue<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for BoundedQueue<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for BoundedQueue<R>
where R: 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.