Struct ringbuf::ring_buffer::SharedRb
source · [−]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
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
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
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.
sourceunsafe fn advance_head(&self, count: usize)
unsafe fn advance_head(&self, count: usize)
Move head position by
count
items forward. Read moresourcefn occupied_ranges(&self) -> (Range<usize>, Range<usize>)
fn occupied_ranges(&self) -> (Range<usize>, Range<usize>)
Returns a pair of ranges of
Self::occupied_slices
location in underlying container.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
sourceunsafe fn advance_tail(&self, count: usize)
unsafe fn advance_tail(&self, count: usize)
Move tail position by
count
items forward. Read moresourcefn vacant_ranges(&self) -> (Range<usize>, Range<usize>)
fn vacant_ranges(&self) -> (Range<usize>, Range<usize>)
Returns a pair of ranges of
Self::vacant_slices
location in underlying container.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
Auto Trait Implementations
Blanket Implementations
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more