pub trait Rb<T>: RbRead<T> + RbWrite<T> {
Show 18 methods
// Provided methods
fn capacity(&self) -> usize { ... }
fn len(&self) -> usize { ... }
fn free_len(&self) -> usize { ... }
fn as_slices(&self) -> (&[T], &[T]) { ... }
fn as_mut_slices(&mut self) -> (&mut [T], &mut [T]) { ... }
fn pop(&mut self) -> Option<T> { ... }
fn pop_iter(&mut self) -> PopIterator<'_, T, RbWrap<Self>> ⓘ { ... }
fn iter(&self) -> Chain<Iter<'_, T>, Iter<'_, T>> { ... }
fn iter_mut(&mut self) -> Chain<IterMut<'_, T>, IterMut<'_, T>> { ... }
fn skip(&mut self, count: usize) -> usize { ... }
fn clear(&mut self) -> usize { ... }
fn push(&mut self, elem: T) -> Result<(), T> { ... }
fn push_overwrite(&mut self, elem: T) -> Option<T> { ... }
fn push_iter<I: Iterator<Item = T>>(&mut self, iter: &mut I) { ... }
fn push_iter_overwrite<I: Iterator<Item = T>>(&mut self, iter: I) { ... }
fn pop_slice(&mut self, elems: &mut [T])
where T: Copy { ... }
fn push_slice(&mut self, elems: &[T])
where T: Copy { ... }
fn push_slice_overwrite(&mut self, elems: &[T])
where T: Copy { ... }
}
Expand description
An abstract ring buffer.
See RbBase
for details of internal implementation of the ring buffer.
This trait contains methods that takes &mut self
allowing you to use ring buffer without splitting it into Producer
and Consumer
.
There are push*_overwrite
methods that cannot be used from Producer
.
The ring buffer can be guarded with mutex or other synchronization primitive and be used from different threads without splitting (but now only in blocking mode, obviously).
Provided Methods§
sourcefn capacity(&self) -> usize
fn capacity(&self) -> usize
Returns capacity of the ring buffer.
The capacity of the buffer is constant.
sourcefn 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.
sourcefn 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.
sourcefn pop(&mut self) -> Option<T>
fn pop(&mut self) -> Option<T>
Removes latest item from the ring buffer and returns it.
Returns None
if the ring buffer is empty.
sourcefn 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.
sourcefn 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.
This iterator does not remove items out of the ring buffer.
sourcefn 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.
This iterator does not remove items out of the ring buffer.
sourcefn skip(&mut self, count: usize) -> usize
fn skip(&mut self, count: usize) -> usize
Removes exactly n
items from the buffer and safely drops them.
Panics if n
is greater than number of items in the ring buffer.
sourcefn clear(&mut self) -> usize
fn clear(&mut self) -> usize
Removes all items from the buffer and safely drops them.
Returns the number of deleted items.
sourcefn push(&mut self, elem: T) -> Result<(), T>
fn push(&mut self, elem: T) -> Result<(), T>
Appends an item to the ring buffer.
On failure returns an Err
containing the item that hasn’t been appended.
sourcefn 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.
Returns overwritten item if overwriting took place.
sourcefn 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.
sourcefn 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.
This method consumes iterator until its end.
Exactly last min(iter.len(), capacity)
items from the iterator will be stored in the ring buffer.
sourcefn pop_slice(&mut self, elems: &mut [T])where
T: Copy,
fn pop_slice(&mut self, elems: &mut [T])where T: Copy,
Removes first items from the ring buffer and writes them into a slice.
Elements must be Copy
.
Panics if slice length is greater than number of items in the ring buffer.
sourcefn push_slice(&mut self, elems: &[T])where
T: Copy,
fn push_slice(&mut self, elems: &[T])where T: Copy,
Appends items from slice to the ring buffer.
Elements must be Copy
.
Panics if slice length is greater than number of free places in the ring buffer.
sourcefn push_slice_overwrite(&mut self, elems: &[T])where
T: Copy,
fn push_slice_overwrite(&mut self, elems: &[T])where T: Copy,
Appends items from slice to the ring buffer overwriting existing items in the ring buffer.
If the slice length is greater than ring buffer capacity then only last capacity
items from slice will be stored in the buffer.