pub struct LocalRb<T, C: Container<T>> { /* private fields */ }
Expand description
Ring buffer for using in single thread.
Does not implement Sync
. And its Producer
and Consumer
do not implement Send
.
This code must fail to compile:
ⓘ
use std::{thread, vec::Vec};
use ringbuf::LocalRb;
let (mut prod, mut cons) = LocalRb::<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> LocalRb<T, Vec<MaybeUninit<T>>>
impl<T> LocalRb<T, Vec<MaybeUninit<T>>>
sourceimpl<T, C: Container<T>> LocalRb<T, C>
impl<T, C: Container<T>> LocalRb<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 LocalRb<T, C>
impl<T, C: Container<T>> RbBase<T> for LocalRb<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
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 LocalRb<T, C>
impl<T, C: Container<T>> RbRead<T> for LocalRb<T, C>
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
sourceimpl<T, C: Container<T>> RbWrite<T> for LocalRb<T, C>
impl<T, C: Container<T>> RbWrite<T> for LocalRb<T, C>
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
impl<T, C: Container<T>> Rb<T> for LocalRb<T, C>
Auto Trait Implementations
impl<T, C> !RefUnwindSafe for LocalRb<T, C>
impl<T, C> Send for LocalRb<T, C>where
C: Send,
T: Send,
impl<T, C> !Sync for LocalRb<T, C>
impl<T, C> Unpin for LocalRb<T, C>where
C: Unpin,
T: Unpin,
impl<T, C> UnwindSafe for LocalRb<T, C>where
C: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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