Skip to main content

Producer

Struct Producer 

Source
pub struct Producer { /* private fields */ }
Expand description

The producer half of the ring buffer. Not Clone — enforces single-producer.

Implementations§

Source§

impl Producer

Source

pub fn push(&self, sample: f32)

Push a sample into the buffer. If the buffer is full, the oldest sample is overwritten.

§Examples
let (p, c) = rt_ring::new(4);
p.push(0.5);
assert_eq!(c.pop(), Some(0.5));
Source

pub fn push_slice(&self, samples: &[f32])

Push a slice of samples into the buffer. Samples that cause overflow overwrite the oldest data.

§Examples
let (p, c) = rt_ring::new(4);
p.push_slice(&[1.0, 2.0, 3.0]);
let mut buf = [0.0f32; 3];
let n = c.pop_slice(&mut buf);
assert_eq!(n, 3);
assert_eq!(&buf, &[1.0, 2.0, 3.0]);
Source

pub fn available(&self) -> usize

Returns the number of samples currently available for reading.

§Examples
let (p, c) = rt_ring::new(4);
assert_eq!(p.available(), 0);
p.push(1.0);
p.push(2.0);
assert_eq!(p.available(), 2);
c.pop();
assert_eq!(p.available(), 1);
Source

pub fn capacity(&self) -> usize

Returns the buffer capacity (always a power of two).

§Examples
let (p, _c) = rt_ring::new(5);
assert_eq!(p.capacity(), 8); // rounded up to next power of two
Source

pub fn overwrite_count(&self) -> u64

Returns the total number of samples that were overwritten since creation.

Equivalent to Consumer::overwrite_count — both read the same atomic counter.

§Examples
let (p, c) = rt_ring::new(4);
for i in 0..10 {
    p.push(i as f32);
}
assert_eq!(p.overwrite_count(), 6);
assert_eq!(p.overwrite_count(), c.overwrite_count());

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.