pub struct EventBuf<T: Copy, const N: usize> { /* private fields */ }Expand description
Bounded SPSC event buffer with backpressure.
When the buffer is full, Producer::push returns Err(val) instead
of overwriting, giving the producer a chance to retry, drop, or log.
The consumer drains items with Consumer::pop or Consumer::drain,
and can inspect the oldest item with Consumer::peek without consuming it.
§Panics
EventBuf::new()panics ifN == 0.producer()/consumer()panic if called while another handle of the same kind is already active. UseEventBuf::try_producer/EventBuf::try_consumerfor a fallible alternative.
Implementations§
Source§impl<T: Copy, const N: usize> EventBuf<T, N>
impl<T: Copy, const N: usize> EventBuf<T, N>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Approximate number of items currently buffered.
Returns a consistent (tail, head) snapshot. The value may still be
stale by the time the caller acts on it, but it will never spuriously
exceed capacity.
This never blocks: it makes a bounded number of attempts and then falls back to a clamped estimate, so a busy consumer cannot stall the caller.
Sourcepub fn try_producer(&self) -> Option<Producer<'_, T, N>>
pub fn try_producer(&self) -> Option<Producer<'_, T, N>>
Try to create the producer handle.
Returns None if a producer is already active. Prefer this over
producer when fallible bring-up is needed.
Sourcepub fn producer(&self) -> Producer<'_, T, N>
pub fn producer(&self) -> Producer<'_, T, N>
Create the producer handle. Only one producer may be active.
§Panics
Panics if a producer handle is already active.
Sourcepub fn try_consumer(&self) -> Option<Consumer<'_, T, N>>
pub fn try_consumer(&self) -> Option<Consumer<'_, T, N>>
Try to create the consumer handle.
Returns None if a consumer is already active. Prefer this over
consumer when fallible bring-up is needed.