Struct ringbuffer::AllocRingBuffer
source · [−]pub struct AllocRingBuffer<T> { /* private fields */ }
Expand description
The AllocRingBuffer
is a RingBufferExt
which is based on a Vec. This means it allocates at runtime
on the heap, and therefore needs the alloc
crate. This struct and therefore the dependency on
alloc can be disabled by disabling the alloc
(default) feature.
Example
use ringbuffer::{AllocRingBuffer, RingBuffer, RingBufferExt, RingBufferWrite};
let mut buffer = AllocRingBuffer::with_capacity(2);
// 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> AllocRingBuffer<T>
impl<T> AllocRingBuffer<T>
sourcepub fn with_capacity_unchecked(cap: usize) -> Self
pub fn with_capacity_unchecked(cap: usize) -> Self
Creates a AllocRingBuffer
with a certain capacity. This capacity is fixed.
for this ringbuffer to work, cap must be a power of two and greater than zero.
sourcepub fn with_capacity_power_of_2(cap_power_of_two: usize) -> Self
pub fn with_capacity_power_of_2(cap_power_of_two: usize) -> Self
Creates a AllocRingBuffer
with a certain capacity. The actual capacity is the input to the
function raised to the power of two (effectively the input is the log2 of the actual capacity)
sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Creates a AllocRingBuffer
with a certain capacity. The capacity must be a power of two.
Panics
Panics when capacity is zero or not a power of two
sourcepub fn new() -> Self
pub fn new() -> Self
Creates an AllocRingBuffer
with a capacity of RINGBUFFER_DEFAULT_CAPACITY
.
Trait Implementations
sourceimpl<T: Clone> Clone for AllocRingBuffer<T>
impl<T: Clone> Clone for AllocRingBuffer<T>
sourceimpl<T: Debug> Debug for AllocRingBuffer<T>
impl<T: Debug> Debug for AllocRingBuffer<T>
sourceimpl<T> Default for AllocRingBuffer<T>
impl<T> Default for AllocRingBuffer<T>
sourcefn default() -> Self
fn default() -> Self
Creates a buffer with a capacity of crate::RINGBUFFER_DEFAULT_CAPACITY
.
sourceimpl<T> Drop for AllocRingBuffer<T>
impl<T> Drop for AllocRingBuffer<T>
sourceimpl<T> Extend<T> for AllocRingBuffer<T>
impl<T> Extend<T> for AllocRingBuffer<T>
sourcefn extend<A: IntoIterator<Item = T>>(&mut self, iter: A)
fn extend<A: IntoIterator<Item = T>>(&mut self, iter: A)
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)sourceimpl<RB> FromIterator<RB> for AllocRingBuffer<RB>
impl<RB> FromIterator<RB> for AllocRingBuffer<RB>
sourcefn from_iter<T: IntoIterator<Item = RB>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = RB>>(iter: T) -> Self
sourceimpl<T> Index<isize> for AllocRingBuffer<T>
impl<T> Index<isize> for AllocRingBuffer<T>
sourceimpl<T> IndexMut<isize> for AllocRingBuffer<T>
impl<T> IndexMut<isize> for AllocRingBuffer<T>
sourceimpl<T: PartialEq> PartialEq<AllocRingBuffer<T>> for AllocRingBuffer<T>
impl<T: PartialEq> PartialEq<AllocRingBuffer<T>> for AllocRingBuffer<T>
sourceimpl<T> RingBuffer<T> for AllocRingBuffer<T>
impl<T> RingBuffer<T> for AllocRingBuffer<T>
sourceimpl<T> RingBufferExt<T> for AllocRingBuffer<T>
impl<T> RingBufferExt<T> for AllocRingBuffer<T>
sourcefn get(&self, index: isize) -> Option<&T>
fn get(&self, index: isize) -> Option<&T>
sourcefn get_mut(&mut self, index: isize) -> Option<&mut T>
fn get_mut(&mut self, index: isize) -> Option<&mut T>
sourcefn get_absolute(&self, index: usize) -> Option<&T>
fn get_absolute(&self, index: usize) -> Option<&T>
Self::get
)sourcefn get_absolute_mut(&mut self, index: usize) -> Option<&mut T>
fn get_absolute_mut(&mut self, index: usize) -> Option<&mut T>
Self::get_mut
)sourcefn clear(&mut self)
fn clear(&mut self)
sourcefn fill_with<F: FnMut() -> T>(&mut self, f: F)
fn fill_with<F: FnMut() -> T>(&mut self, f: F)
sourcefn peek(&self) -> Option<&T>
fn peek(&self) -> Option<&T>
Self::front
) Read more