Skip to main content

EventBuf

Struct EventBuf 

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

§Panics

  • EventBuf::new() panics if N == 0.
  • producer() / consumer() panic if called while another handle of the same kind is already active.

Implementations§

Source§

impl<T: Copy, const N: usize> EventBuf<T, N>

Source

pub fn new() -> Self

Create a new, empty event buffer.

§Panics

Panics if N == 0.

Source

pub const fn capacity(&self) -> usize

Maximum number of items the buffer can hold.

Source

pub fn len(&self) -> usize

Approximate number of items currently buffered.

This is a snapshot — by the time the caller acts on it the value may already be stale.

Source

pub fn is_empty(&self) -> bool

Returns true if the buffer contains no items (approximate).

Source

pub fn is_full(&self) -> bool

Returns true if the buffer is at capacity (approximate).

Source

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.

Source

pub fn consumer(&self) -> Consumer<'_, T, N>

Create the consumer handle. Only one consumer may be active.

§Panics

Panics if a consumer handle is already active.

Trait Implementations§

Source§

impl<T: Copy, const N: usize> Debug for EventBuf<T, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Copy, const N: usize> Default for EventBuf<T, N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Copy + Send, const N: usize> Sync for EventBuf<T, N>

Auto Trait Implementations§

§

impl<T, const N: usize> !Freeze for EventBuf<T, N>

§

impl<T, const N: usize> !RefUnwindSafe for EventBuf<T, N>

§

impl<T, const N: usize> Send for EventBuf<T, N>
where T: Send,

§

impl<T, const N: usize> Unpin for EventBuf<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for EventBuf<T, N>
where T: 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.