pub struct Producer { /* private fields */ }Expand description
The producer half of the ring buffer. Not Clone — enforces single-producer.
Implementations§
Source§impl Producer
impl Producer
Sourcepub fn push(&self, sample: f32)
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));Sourcepub fn push_slice(&self, samples: &[f32])
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]);Sourcepub fn available(&self) -> usize
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);Sourcepub fn capacity(&self) -> usize
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 twoSourcepub fn overwrite_count(&self) -> u64
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§
impl Freeze for Producer
impl RefUnwindSafe for Producer
impl Send for Producer
impl Sync for Producer
impl Unpin for Producer
impl UnsafeUnpin for Producer
impl UnwindSafe for Producer
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