Struct rtrb::RingBuffer

source ·
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>

source

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(()));
source

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> Debug for RingBuffer<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Drop for RingBuffer<T>

source§

fn drop(&mut self)

Drops all non-empty slots.

source§

impl<T> PartialEq for RingBuffer<T>

source§

fn eq(&self, other: &Self) -> 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());
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Eq for RingBuffer<T>

Auto Trait Implementations§

§

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: UnwindSafe + RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.