[][src]Struct spms_ring::SpmsRing

pub struct SpmsRing<T, N: ArrayLength<T>> { /* fields omitted */ }

This is a ring buffer intended for use in pub-sub applications. That is, a single publisher writes items to the buffer, and multiple subscribers can read items from the buffer. When a write to the fixed-size circular buffer overflows, the oldest items in the buffer are overwritten. Reading items from the buffer does not remove them from the buffer (as it would from a Queue): instead, Subscribers use ReadTokens to track which items they have already read, and use nonblocking read to read the next available item.

Note that the fixed buffer length must always be a power of two.

Implementations

impl<T, N> SpmsRing<T, N> where
    T: Default + Copy + Debug,
    N: ArrayLength<T>, 
[src]

pub fn subscribe(&self) -> ReadToken[src]

Get a read token for subsequent reads

pub fn publish(&mut self, val: &T)[src]

Publish a single item

pub fn read_next(&self, token: &mut ReadToken) -> Result<T, ()>[src]

Read an item from the buffer. Returns either an available item or WouldBlock There are only three possible actions:

  • Read from the next available index after index in read token
  • Read from oldest index (the read token might be stale)
  • nb::Error::WouldBlock

pub fn empty(&self) -> bool[src]

Is the queue empty?

pub fn at_capacity(&self) -> bool[src]

Is this buffer filled to capacity? In other words, will a subsequent publish overwrite the oldest item in the buffer?

pub fn available(&self) -> usize[src]

How many total items are available to read?

Trait Implementations

impl<T, N> Default for SpmsRing<T, N> where
    T: Default + Copy + Debug,
    N: ArrayLength<T>, 
[src]

fn default() -> Self[src]

This is how the buffer should be created

Auto Trait Implementations

impl<T, N> Send for SpmsRing<T, N> where
    T: Send

impl<T, N> Sync for SpmsRing<T, N> where
    T: Sync

impl<T, N> Unpin for SpmsRing<T, N> where
    <N as ArrayLength<T>>::ArrayType: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.