pub struct CBuf<T> { /* private fields */ }Expand description
Bounded SPSC ring queue.
CBuf mirrors the contract of the C CBUF_* macro family while
remaining safe to use across multiple producers or consumers (the
underlying ArrayQueue is MPMC). A new ring of capacity N admits
up to N elements before push starts returning
Err.
Implementations§
Source§impl<T> CBuf<T>
impl<T> CBuf<T>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a ring with room for exactly capacity elements.
§Panics
Panics if capacity == 0 (matching the precondition on
ArrayQueue::new).
§Examples
use dynomite::io::cbuf::CBuf;
let q: CBuf<u8> = CBuf::new(8);
assert_eq!(q.capacity(), 8);Sourcepub fn push(&self, item: T) -> Result<(), T>
pub fn push(&self, item: T) -> Result<(), T>
Append an element. Returns Err(item) when the ring is full,
echoing try_send on bounded channels. Mirrors CBUF_Push
(the C version overwrites silently on overflow; the Rust
version reports the failure so callers cannot lose data
inadvertently).
§Examples
use dynomite::io::cbuf::CBuf;
let q: CBuf<u8> = CBuf::new(2);
q.push(1).unwrap();
q.push(2).unwrap();
assert_eq!(q.push(3), Err(3));Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for CBuf<T>
impl<T> RefUnwindSafe for CBuf<T>
impl<T> Send for CBuf<T>where
T: Send,
impl<T> Sync for CBuf<T>where
T: Send,
impl<T> Unpin for CBuf<T>
impl<T> UnsafeUnpin for CBuf<T>
impl<T> UnwindSafe for CBuf<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more