[−][src]Struct spms_ring::SpmsRing
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]
T: Default + Copy + Debug,
N: ArrayLength<T>,
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
Auto Trait Implementations
impl<T, N> Send for SpmsRing<T, N> where
T: Send,
T: Send,
impl<T, N> Sync for SpmsRing<T, N> where
T: Sync,
T: Sync,
impl<T, N> Unpin for SpmsRing<T, N> where
<N as ArrayLength<T>>::ArrayType: Unpin,
<N as ArrayLength<T>>::ArrayType: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,