Struct ringbuffer::ConstGenericRingBuffer
source · [−]pub struct ConstGenericRingBuffer<T, const CAP: usize> { /* private fields */ }Expand description
The ConstGenericRingBuffer struct is a RingBuffer implementation which does not require alloc but
uses const generics instead.
ConstGenericRingBuffer allocates the ringbuffer on the stack, and the size must be known at
compile time through const-generics.
Example
use ringbuffer::{ConstGenericRingBuffer, RingBuffer, RingBufferExt, RingBufferWrite};
let mut buffer = ConstGenericRingBuffer::<_, 2>::new();
// First entry of the buffer is now 5.
buffer.push(5);
// The last item we pushed is 5
assert_eq!(buffer.get(-1), Some(&5));
// Second entry is now 42.
buffer.push(42);
assert_eq!(buffer.peek(), Some(&5));
assert!(buffer.is_full());
// Because capacity is reached the next push will be the first item of the buffer.
buffer.push(1);
assert_eq!(buffer.to_vec(), vec![42, 1]);Implementations
sourceimpl<T, const CAP: usize> ConstGenericRingBuffer<T, CAP>
impl<T, const CAP: usize> ConstGenericRingBuffer<T, CAP>
Trait Implementations
sourceimpl<T: Clone, const CAP: usize> Clone for ConstGenericRingBuffer<T, CAP>
impl<T: Clone, const CAP: usize> Clone for ConstGenericRingBuffer<T, CAP>
sourceimpl<T: Debug, const CAP: usize> Debug for ConstGenericRingBuffer<T, CAP>
impl<T: Debug, const CAP: usize> Debug for ConstGenericRingBuffer<T, CAP>
sourceimpl<T, const CAP: usize> Default for ConstGenericRingBuffer<T, CAP>
impl<T, const CAP: usize> Default for ConstGenericRingBuffer<T, CAP>
sourceimpl<T, const CAP: usize> Drop for ConstGenericRingBuffer<T, CAP>
impl<T, const CAP: usize> Drop for ConstGenericRingBuffer<T, CAP>
sourceimpl<T, const CAP: usize> Extend<T> for ConstGenericRingBuffer<T, CAP>
impl<T, const CAP: usize> Extend<T> for ConstGenericRingBuffer<T, CAP>
sourcefn extend<A: IntoIterator<Item = T>>(&mut self, iter: A)
fn extend<A: IntoIterator<Item = T>>(&mut self, iter: A)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<RB, const CAP: usize> FromIterator<RB> for ConstGenericRingBuffer<RB, CAP>
impl<RB, const CAP: usize> FromIterator<RB> for ConstGenericRingBuffer<RB, CAP>
sourcefn from_iter<T: IntoIterator<Item = RB>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = RB>>(iter: T) -> Self
Creates a value from an iterator. Read more
sourceimpl<T, const CAP: usize> Index<isize> for ConstGenericRingBuffer<T, CAP>
impl<T, const CAP: usize> Index<isize> for ConstGenericRingBuffer<T, CAP>
sourceimpl<T, const CAP: usize> IndexMut<isize> for ConstGenericRingBuffer<T, CAP>
impl<T, const CAP: usize> IndexMut<isize> for ConstGenericRingBuffer<T, CAP>
sourceimpl<T: PartialEq, const CAP: usize> PartialEq<ConstGenericRingBuffer<T, CAP>> for ConstGenericRingBuffer<T, CAP>
impl<T: PartialEq, const CAP: usize> PartialEq<ConstGenericRingBuffer<T, CAP>> for ConstGenericRingBuffer<T, CAP>
sourceimpl<T, const CAP: usize> RingBuffer<T> for ConstGenericRingBuffer<T, CAP>
impl<T, const CAP: usize> RingBuffer<T> for ConstGenericRingBuffer<T, CAP>
sourceimpl<T, const CAP: usize> RingBufferExt<T> for ConstGenericRingBuffer<T, CAP>
impl<T, const CAP: usize> RingBufferExt<T> for ConstGenericRingBuffer<T, CAP>
sourcefn get(&self, index: isize) -> Option<&T>
fn get(&self, index: isize) -> Option<&T>
Gets a value relative to the current index. 0 is the next index to be written to with push.
-1 and down are the last elements pushed and 0 and up are the items that were pushed the longest ago. Read more
sourcefn get_mut(&mut self, index: isize) -> Option<&mut T>
fn get_mut(&mut self, index: isize) -> Option<&mut T>
Gets a value relative to the current index mutably. 0 is the next index to be written to with push.
-1 and down are the last elements pushed and 0 and up are the items that were pushed the longest ago. Read more
sourcefn get_absolute(&self, index: usize) -> Option<&T>
fn get_absolute(&self, index: usize) -> Option<&T>
Gets a value relative to the start of the array (rarely useful, usually you want
Self::get)sourcefn get_absolute_mut(&mut self, index: usize) -> Option<&mut T>
fn get_absolute_mut(&mut self, index: usize) -> Option<&mut T>
Gets a value mutably relative to the start of the array (rarely useful, usually you want
Self::get_mut)sourcefn clear(&mut self)
fn clear(&mut self)
Empties the buffer entirely. Sets the length to 0 but keeps the capacity allocated.
sourcefn fill_with<F: FnMut() -> T>(&mut self, f: F)
fn fill_with<F: FnMut() -> T>(&mut self, f: F)
Sets every element in the ringbuffer to the value returned by f.
sourcefn peek(&self) -> Option<&T>
fn peek(&self) -> Option<&T>
Returns the value at the current index.
This is the value that will be overwritten by the next push and also the value pushed
the longest ago. (alias of
Self::front) Read moresourcefn front(&self) -> Option<&T>
fn front(&self) -> Option<&T>
Returns the value at the front of the queue.
This is the value that will be overwritten by the next push and also the value pushed
the longest ago.
(alias of peek) Read more
sourcefn front_mut(&mut self) -> Option<&mut T>
fn front_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the value at the back of the queue.
This is the value that will be overwritten by the next push.
(alias of peek) Read more
sourcefn back(&self) -> Option<&T>
fn back(&self) -> Option<&T>
Returns the value at the back of the queue.
This is the item that was pushed most recently. Read more
sourcefn back_mut(&mut self) -> Option<&mut T>
fn back_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the value at the back of the queue.
This is the item that was pushed most recently. Read more
sourceimpl<T, const CAP: usize> RingBufferRead<T> for ConstGenericRingBuffer<T, CAP>
impl<T, const CAP: usize> RingBufferRead<T> for ConstGenericRingBuffer<T, CAP>
sourceimpl<T, const CAP: usize> RingBufferWrite<T> for ConstGenericRingBuffer<T, CAP>
impl<T, const CAP: usize> RingBufferWrite<T> for ConstGenericRingBuffer<T, CAP>
impl<T: PartialEq, const CAP: usize> Eq for ConstGenericRingBuffer<T, CAP>
Auto Trait Implementations
impl<T, const CAP: usize> RefUnwindSafe for ConstGenericRingBuffer<T, CAP>where
T: RefUnwindSafe,
impl<T, const CAP: usize> Send for ConstGenericRingBuffer<T, CAP>where
T: Send,
impl<T, const CAP: usize> Sync for ConstGenericRingBuffer<T, CAP>where
T: Sync,
impl<T, const CAP: usize> Unpin for ConstGenericRingBuffer<T, CAP>where
T: Unpin,
impl<T, const CAP: usize> UnwindSafe for ConstGenericRingBuffer<T, CAP>where
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