pub struct Consumer<'a, T: Copy, const N: usize> { /* private fields */ }Expand description
Consumer handle for reading from the ring.
This handle is !Sync to prevent concurrent consumers.
Implementations§
Source§impl<'a, T: Copy, const N: usize> Consumer<'a, T, N>
impl<'a, T: Copy, const N: usize> Consumer<'a, T, N>
Sourcepub fn dropped(&self) -> usize
pub fn dropped(&self) -> usize
How many items have been dropped since consumer creation (or since reset).
The counter saturates at usize::MAX rather than wrapping, so on a
32-bit target a very long-lived lagging consumer reports “at least this
many” instead of overflowing. Call reset_dropped
periodically if exact long-run totals matter.
Sourcepub fn reset_dropped(&mut self)
pub fn reset_dropped(&mut self)
Reset the internal drop counter.
Sourcepub fn poll_one(&mut self, hook: impl FnOnce(u32, &T)) -> bool
pub fn poll_one(&mut self, hook: impl FnOnce(u32, &T)) -> bool
Drain at most one item (in-order). Bounded per call — this is
poll_up_to(1, …) and inherits its frozen
entry-sample window.
Returns true if an item was delivered to the hook.
Sourcepub fn poll_one_value(&mut self) -> Option<(u32, T)>
pub fn poll_one_value(&mut self) -> Option<(u32, T)>
Drain at most one item (in-order), returning (seq, value).
Equivalent to poll_one without a hook. Drop
accounting and the read + dropped invariant are unchanged.
Sourcepub fn poll_up_to(&mut self, max: usize, hook: impl FnMut(u32, &T)) -> PollStats
pub fn poll_up_to(&mut self, max: usize, hook: impl FnMut(u32, &T)) -> PollStats
Drain up to max items (in-order) from the window that existed when
the call began.
Hook sees &T but it is a reference to a local copy inside poll.
The newest published sequence is sampled once at entry and the
drain stops there: items the producer publishes while the poll runs
wait for the next call, and nothing is lost or double-counted by the
hand-off. Freezing the goal is what makes every call bounded — at
most one lag-recovery jump plus a walk of at most N slots plus
max reads, regardless of how fast the producer publishes. (The
previous formulation re-read the newest sequence every iteration, so
a producer that stayed ahead could starve the poll indefinitely.)
If max == 0, this returns immediately with read = 0, dropped = 0, and
newest set to the latest published sequence. Otherwise
PollStats::newest reports the entry sample the drain ran against.
Sourcepub fn latest(&self, hook: impl FnOnce(u32, &T)) -> bool
pub fn latest(&self, hook: impl FnOnce(u32, &T)) -> bool
“Give me the newest thing right now” (not in-order). Returns true if it delivered something.
This does not advance the consumer cursor.
Sourcepub fn latest_value(&self) -> Option<(u32, T)>
pub fn latest_value(&self) -> Option<(u32, T)>
Read the newest item without a hook, returning (seq, value).
Equivalent to latest. Does not advance the consumer
cursor.
Sourcepub fn skip_to_latest(&mut self)
pub fn skip_to_latest(&mut self)
Fast-forward consumer so the next poll_one() yields the newest item
(i.e. skip backlog).
This does not modify the dropped counter.