Struct ringbuf::ring_buffer::LocalRb
source · 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§
source§impl<T> LocalRb<T, Vec<MaybeUninit<T>>>
impl<T> LocalRb<T, Vec<MaybeUninit<T>>>
source§impl<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§
source§impl<T, C: Container<T>> Rb<T> for LocalRb<T, C>
impl<T, C: Container<T>> Rb<T> for LocalRb<T, C>
source§fn as_slices(&self) -> (&[T], &[T])
fn as_slices(&self) -> (&[T], &[T])
Returns a pair of slices which contain, in order, the contents of the ring buffer.
source§fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])
fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])
Returns a pair of mutable slices which contain, in order, the contents of the ring buffer.
source§fn pop(&mut self) -> Option<T>
fn pop(&mut self) -> Option<T>
Removes latest item from the ring buffer and returns it. Read more
source§fn pop_iter(&mut self) -> PopIterator<'_, T, RbWrap<Self>> ⓘ
fn pop_iter(&mut self) -> PopIterator<'_, T, RbWrap<Self>> ⓘ
Returns an iterator that removes items one by one from the ring buffer.
source§fn iter(&self) -> Chain<Iter<'_, T>, Iter<'_, T>>
fn iter(&self) -> Chain<Iter<'_, T>, Iter<'_, T>>
Returns a front-to-back iterator containing references to items in the ring buffer. Read more
source§fn iter_mut(&mut self) -> Chain<IterMut<'_, T>, IterMut<'_, T>>
fn iter_mut(&mut self) -> Chain<IterMut<'_, T>, IterMut<'_, T>>
Returns a front-to-back iterator that returns mutable references to items in the ring buffer. Read more
source§fn skip(&mut self, count: usize) -> usize
fn skip(&mut self, count: usize) -> usize
Removes exactly
n
items from the buffer and safely drops them. Read moresource§fn clear(&mut self) -> usize
fn clear(&mut self) -> usize
Removes all items from the buffer and safely drops them. Read more
source§fn push_overwrite(&mut self, elem: T) -> Option<T>
fn push_overwrite(&mut self, elem: T) -> Option<T>
Pushes an item to the ring buffer overwriting the latest item if the buffer is full. Read more
source§fn push_iter<I: Iterator<Item = T>>(&mut self, iter: &mut I)
fn push_iter<I: Iterator<Item = T>>(&mut self, iter: &mut I)
Appends items from an iterator to the ring buffer.
Elements that haven’t been added to the ring buffer remain in the iterator.
source§fn push_iter_overwrite<I: Iterator<Item = T>>(&mut self, iter: I)
fn push_iter_overwrite<I: Iterator<Item = T>>(&mut self, iter: I)
Appends items from an iterator to the ring buffer. Read more
source§impl<T, C: Container<T>> RbBase<T> for LocalRb<T, C>
impl<T, C: Container<T>> RbBase<T> for LocalRb<T, C>
source§unsafe fn slices(
&self,
head: usize,
tail: usize
) -> (&mut [MaybeUninit<T>], &mut [MaybeUninit<T>])
unsafe fn slices( &self, head: usize, tail: usize ) -> (&mut [MaybeUninit<T>], &mut [MaybeUninit<T>])
Returns part of underlying raw ring buffer memory as slices. Read more
source§fn capacity_nonzero(&self) -> NonZeroUsize
fn capacity_nonzero(&self) -> NonZeroUsize
Capacity of the ring buffer. Read more
source§fn modulus(&self) -> NonZeroUsize
fn modulus(&self) -> NonZeroUsize
source§fn occupied_len(&self) -> usize
fn occupied_len(&self) -> usize
The number of items stored in the buffer at the moment.
source§fn vacant_len(&self) -> usize
fn vacant_len(&self) -> usize
The number of vacant places in the buffer at the moment.
source§impl<T, C: Container<T>> RbRead<T> for LocalRb<T, C>
impl<T, C: Container<T>> RbRead<T> for LocalRb<T, C>
source§unsafe fn advance_head(&self, count: usize)
unsafe fn advance_head(&self, count: usize)
Move head position by
count
items forward. Read moresource§fn 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.source§unsafe 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
source§impl<T, C: Container<T>> RbWrite<T> for LocalRb<T, C>
impl<T, C: Container<T>> RbWrite<T> for LocalRb<T, C>
source§unsafe fn advance_tail(&self, count: usize)
unsafe fn advance_tail(&self, count: usize)
Move tail position by
count
items forward. Read moresource§fn 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.source§unsafe 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