Struct ringbuffer::ConstGenericRingBuffer [−][src]
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
impl<T, const CAP: usize> ConstGenericRingBuffer<T, CAP>
[src]
pub fn new() -> Self
[src]
Creates a new RingBuffer
. This method simply creates a default ringbuffer. The capacity is given as a
type parameter.
Trait Implementations
impl<T: Clone, const CAP: usize> Clone for ConstGenericRingBuffer<T, CAP>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug, const CAP: usize> Debug for ConstGenericRingBuffer<T, CAP>
[src]
impl<T, const CAP: usize> Default for ConstGenericRingBuffer<T, CAP>
[src]
fn default() -> Self
[src]
Creates a buffer with a capacity specified through the Cap type parameter.
Panics
Panics if CAP
is 0 or not a power of two
impl<T: PartialEq, const CAP: usize> Eq for ConstGenericRingBuffer<T, CAP>
[src]
impl<RB, const CAP: usize> FromIterator<RB> for ConstGenericRingBuffer<RB, CAP>
[src]
fn from_iter<T: IntoIterator<Item = RB>>(iter: T) -> Self
[src]
impl<T, const CAP: usize> Index<isize> for ConstGenericRingBuffer<T, CAP>
[src]
type Output = T
The returned type after indexing.
fn index(&self, index: isize) -> &Self::Output
[src]
impl<T, const CAP: usize> IndexMut<isize> for ConstGenericRingBuffer<T, CAP>
[src]
impl<T: PartialEq, const CAP: usize> PartialEq<ConstGenericRingBuffer<T, CAP>> for ConstGenericRingBuffer<T, CAP>
[src]
impl<T, const CAP: usize> RingBuffer<T> for ConstGenericRingBuffer<T, CAP>
[src]
fn capacity(&self) -> usize
[src]
fn len(&self) -> usize
[src]
fn is_empty(&self) -> bool
[src]
fn is_full(&self) -> bool
[src]
impl<T, const CAP: usize> RingBufferExt<T> for ConstGenericRingBuffer<T, CAP>
[src]
fn get(&self, index: isize) -> Option<&T>
[src]
fn get_mut(&mut self, index: isize) -> Option<&mut T>
[src]
fn get_absolute(&self, index: usize) -> Option<&T>
[src]
fn get_absolute_mut(&mut self, index: usize) -> Option<&mut T>
[src]
fn clear(&mut self)
[src]
fn peek(&self) -> Option<&T>
[src]
fn front(&self) -> Option<&T>
[src]
fn front_mut(&mut self) -> Option<&mut T>
[src]
fn back(&self) -> Option<&T>
[src]
fn back_mut(&mut self) -> Option<&mut T>
[src]
fn iter_mut(&mut self) -> RingBufferMutIterator<'_, T, Self>
[src]
fn iter(&self) -> RingBufferIterator<'_, T, Self>
[src]
fn to_vec(&self) -> Vec<T> where
T: Clone,
[src]
T: Clone,
fn contains(&self, elem: &T) -> bool where
T: PartialEq,
[src]
T: PartialEq,
impl<T, const CAP: usize> RingBufferRead<T> for ConstGenericRingBuffer<T, CAP>
[src]
fn dequeue_ref(&mut self) -> Option<&T>
[src]
fn skip(&mut self)
[src]
fn dequeue(&mut self) -> Option<T> where
T: Clone,
[src]
T: Clone,
fn drain(&mut self) -> RingBufferDrainingIterator<'_, T, Self> where
T: Clone,
[src]
T: Clone,
impl<T, const CAP: usize> RingBufferWrite<T> for ConstGenericRingBuffer<T, CAP>
[src]
Auto Trait Implementations
impl<T, const CAP: usize> Send for ConstGenericRingBuffer<T, CAP> where
T: Send,
T: Send,
impl<T, const CAP: usize> Sync for ConstGenericRingBuffer<T, CAP> where
T: Sync,
T: Sync,
impl<T, const CAP: usize> Unpin for ConstGenericRingBuffer<T, CAP> where
T: Unpin,
T: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,