pub struct SpscConsumer<T, const N: usize> { /* private fields */ }Expand description
Consumer half of a split SpscRing.
Implementations§
Source§impl<T, const N: usize> SpscConsumer<T, N>
impl<T, const N: usize> SpscConsumer<T, N>
Sourcepub fn pop(&self) -> Result<T, StreamError>
pub fn pop(&self) -> Result<T, StreamError>
Pop an item from the ring. See SpscRing::pop.
Sourcepub fn drain(&self) -> Vec<T>
pub fn drain(&self) -> Vec<T>
Drain all items currently in the ring into a Vec, in FIFO order.
Useful for clean shutdown: call drain() after the producer has
stopped to collect any in-flight items before dropping the consumer.
§Complexity: O(n) where n is the number of items drained.
Sourcepub fn fill_ratio(&self) -> f64
pub fn fill_ratio(&self) -> f64
Fraction of capacity currently occupied: len / capacity.
Returns a value in [0.0, 1.0]. Useful for backpressure monitoring.
Sourcepub fn peek_clone(&self) -> Option<T>where
T: Clone,
pub fn peek_clone(&self) -> Option<T>where
T: Clone,
Clone the next item without removing it.
Returns None if the ring is empty. See SpscRing::peek_clone.
§Complexity: O(1).
Sourcepub fn try_pop_n(&self, max: usize) -> Vec<T>
pub fn try_pop_n(&self, max: usize) -> Vec<T>
Pop at most max items from the ring in FIFO order, returning them as a Vec.
Unlike drain, this stops after max items even if more
are available — useful for bounded batch processing where a consumer must
not block indefinitely draining a fast producer.
§Complexity: O(min(n, max)) where n is the current queue length.
Sourcepub fn into_iter_drain(self) -> SpscDrainIter<T, N> ⓘ
pub fn into_iter_drain(self) -> SpscDrainIter<T, N> ⓘ
Return a by-value iterator that pops items from the ring in FIFO order.
Unlike drain, this does not collect into a Vec — items
are yielded lazily on each call to next().