pub struct RingBuffer<T> { /* private fields */ }Expand description
A bounded single-producer single-consumer (SPSC) queue.
Elements can be written with a Producer and read with a Consumer,
both of which can be obtained with RingBuffer::new().
See also the crate-level documentation.
Implementations§
Source§impl<T> RingBuffer<T>
 
impl<T> RingBuffer<T>
Sourcepub fn new(capacity: usize) -> (Producer<T>, Consumer<T>)
 
pub fn new(capacity: usize) -> (Producer<T>, Consumer<T>)
Creates a RingBuffer with the given capacity and returns Producer and Consumer.
§Examples
use rtrb::RingBuffer;
let (producer, consumer) = RingBuffer::<f32>::new(100);Specifying an explicit type with the turbofish is is only necessary if it cannot be deduced by the compiler.
use rtrb::RingBuffer;
let (mut producer, consumer) = RingBuffer::new(100);
assert_eq!(producer.push(0.0f32), Ok(()));Sourcepub fn capacity(&self) -> usize
 
pub fn capacity(&self) -> usize
Returns the capacity of the queue.
§Examples
use rtrb::RingBuffer;
let (producer, consumer) = RingBuffer::<f32>::new(100);
assert_eq!(producer.buffer().capacity(), 100);
assert_eq!(consumer.buffer().capacity(), 100);
// Both producer and consumer of course refer to the same ring buffer:
assert_eq!(producer.buffer(), consumer.buffer());Trait Implementations§
Source§impl<T> Debug for RingBuffer<T>where
    T: Debug,
 
impl<T> Debug for RingBuffer<T>where
    T: Debug,
Source§impl<T> PartialEq for RingBuffer<T>
 
impl<T> PartialEq for RingBuffer<T>
Source§fn eq(&self, other: &RingBuffer<T>) -> bool
 
fn eq(&self, other: &RingBuffer<T>) -> bool
This method tests for self and other values to be equal, and is used by ==.
§Examples
use rtrb::RingBuffer;
let (p1, c1) = RingBuffer::<f32>::new(1000);
assert_eq!(p1.buffer(), c1.buffer());
let (p2, c2) = RingBuffer::<f32>::new(1000);
assert_ne!(p1.buffer(), p2.buffer());impl<T> Eq for RingBuffer<T>
Auto Trait Implementations§
impl<T> !Freeze for RingBuffer<T>
impl<T> RefUnwindSafe for RingBuffer<T>where
    T: RefUnwindSafe,
impl<T> !Send for RingBuffer<T>
impl<T> !Sync for RingBuffer<T>
impl<T> Unpin for RingBuffer<T>where
    T: Unpin,
impl<T> UnwindSafe for RingBuffer<T>where
    T: RefUnwindSafe + UnwindSafe,
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