pub struct SharedRb<T, C: Container<T>> { /* private fields */ }
Expand description
Ring buffer that could be shared between threads.
Implements Sync
. And its Producer
and Consumer
implement Send
.
use std::{thread, vec::Vec};
use ringbuf::SharedRb;
let (mut prod, mut cons) = SharedRb::<i32, Vec<_>>::new(256).split();
thread::spawn(move || {
prod.push(123).unwrap();
})
.join();
thread::spawn(move || {
assert_eq!(cons.pop().unwrap(), 123);
})
.join();
Implementations
sourceimpl<T> SharedRb<T, Vec<MaybeUninit<T>>>
impl<T> SharedRb<T, Vec<MaybeUninit<T>>>
sourceimpl<T, C: Container<T>> SharedRb<T, C>
impl<T, C: Container<T>> SharedRb<T, C>
sourcepub unsafe fn from_raw_parts(container: C, head: usize, tail: usize) -> Self
pub unsafe fn from_raw_parts(container: C, head: usize, tail: usize) -> Self
sourcepub unsafe fn into_raw_parts(self) -> (C, usize, usize)
pub unsafe fn into_raw_parts(self) -> (C, usize, usize)
Destructures ring buffer into underlying container and head
and tail
counters.
Safety
Initialized contents of the container must be properly dropped.
Trait Implementations
sourceimpl<T, C: Container<T>> RbBase<T> for SharedRb<T, C>
impl<T, C: Container<T>> RbBase<T> for SharedRb<T, C>
sourceunsafe fn data(&self) -> &mut [MaybeUninit<T>]
unsafe fn data(&self) -> &mut [MaybeUninit<T>]
Returns underlying raw ring buffer memory as slice. Read more
sourcefn capacity(&self) -> NonZeroUsize
fn capacity(&self) -> NonZeroUsize
Capacity of the ring buffer. Read more
sourcefn modulus(&self) -> NonZeroUsize
fn modulus(&self) -> NonZeroUsize
Modulus for head
and tail
values. Read more
sourcefn occupied_len(&self) -> usize
fn occupied_len(&self) -> usize
The number of items stored in the buffer at the moment.
sourcefn vacant_len(&self) -> usize
fn vacant_len(&self) -> usize
The number of vacant places in the buffer at the moment.
sourceimpl<T, C: Container<T>> RbRead<T> for SharedRb<T, C>
impl<T, C: Container<T>> RbRead<T> for SharedRb<T, C>
sourceunsafe fn advance_head(&self, count: usize)
unsafe fn advance_head(&self, count: usize)
Move head position by count
items forward. Read more
sourcefn occupied_ranges(&self) -> (Range<usize>, Range<usize>)
fn occupied_ranges(&self) -> (Range<usize>, Range<usize>)
Returns a pair of slices which contain, in order, the occupied cells in the ring buffer. Read more
sourceunsafe fn occupied_slices(
&self
) -> (&mut [MaybeUninit<T>], &mut [MaybeUninit<T>])
unsafe fn occupied_slices(
&self
) -> (&mut [MaybeUninit<T>], &mut [MaybeUninit<T>])
Provides a direct mutable access to the ring buffer occupied memory. Read more
sourceimpl<T, C: Container<T>> RbWrite<T> for SharedRb<T, C>
impl<T, C: Container<T>> RbWrite<T> for SharedRb<T, C>
sourceunsafe fn advance_tail(&self, count: usize)
unsafe fn advance_tail(&self, count: usize)
Move tail position by count
items forward. Read more
sourcefn vacant_ranges(&self) -> (Range<usize>, Range<usize>)
fn vacant_ranges(&self) -> (Range<usize>, Range<usize>)
Returns a pair of slices which contain, in order, the vacant cells in the ring buffer. Read more
sourceunsafe fn vacant_slices(&self) -> (&mut [MaybeUninit<T>], &mut [MaybeUninit<T>])
unsafe fn vacant_slices(&self) -> (&mut [MaybeUninit<T>], &mut [MaybeUninit<T>])
Provides a direct access to the ring buffer vacant memory. Returns a pair of slices of uninitialized memory, the second one may be empty. Read more
impl<T, C: Container<T>> Rb<T> for SharedRb<T, C>
Auto Trait Implementations
impl<T, C> !RefUnwindSafe for SharedRb<T, C>
impl<T, C> Send for SharedRb<T, C> where
C: Send,
T: Send,
impl<T, C> Sync for SharedRb<T, C> where
T: Send,
impl<T, C> Unpin for SharedRb<T, C> where
C: Unpin,
T: Unpin,
impl<T, C> UnwindSafe for SharedRb<T, C> where
C: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more