Struct rtrb::RingBuffer [−][src]
pub struct RingBuffer<T> { /* fields omitted */ }
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
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(()));
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
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());