pub struct RingBuffer<T: Send + 'static> { /* 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

Creates a RingBuffer with the given capacity and returns Producer and Consumer.

Examples
use rtrb_basedrop::RingBuffer;
use basedrop::Collector;

let collector = Collector::new();

let (producer, consumer) = RingBuffer::<f32>::new(100, &collector.handle());

Specifying an explicit type with the turbofish is is only necessary if it cannot be deduced by the compiler.

use rtrb_basedrop::RingBuffer;
use basedrop::Collector;

let collector = Collector::new();

let (mut producer, consumer) = RingBuffer::new(100, &collector.handle());
assert_eq!(producer.push(0.0f32), Ok(()));

Returns the capacity of the queue.

Examples
use rtrb_basedrop::RingBuffer;
use basedrop::Collector;

let collector = Collector::new();

let (producer, consumer) = RingBuffer::<f32>::new(100, &collector.handle());
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

Formats the value using the given formatter. Read more

Drops all non-empty slots.

This method tests for self and other values to be equal, and is used by ==.

Examples
use rtrb_basedrop::RingBuffer;
use basedrop::Collector;

let collector = Collector::new();

let (p1, c1) = RingBuffer::<f32>::new(1000, &collector.handle());
assert_eq!(p1.buffer(), c1.buffer());

let (p2, c2) = RingBuffer::<f32>::new(1000, &collector.handle());
assert_ne!(p1.buffer(), p2.buffer());

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.