pub struct CircularBuffer<T> { /* private fields */ }Expand description
Fixed size circular/cyclic/ring buffer
A FIFO (first in, first out) queue. It cannot represent an empty buffer.
When constructed, the internal list must not be empty, and cannot contain invalid (e.g. uninitialized) elements.
Implementations§
Source§impl<T> CircularBuffer<T>
impl<T> CircularBuffer<T>
Sourcepub fn queue(&mut self, elem: T) -> T
pub fn queue(&mut self, elem: T) -> T
Enqueues (push at beginning) the given element at the beginning of the buffer Dequeues (pop at end) the last element and returns it This keeps the the buffer length
Sourcepub fn set_first(&mut self, index: usize)
pub fn set_first(&mut self, index: usize)
Sets the offset for the first element, relative to the currently first element
When index is out of range, it loops around
Sourcepub fn get(&self, index: usize) -> &T
pub fn get(&self, index: usize) -> &T
Returns a reference to the element at the given index
When index is out of range, it loops around
Sourcepub fn get_mut(&mut self, index: usize) -> &mut T
pub fn get_mut(&mut self, index: usize) -> &mut T
Returns a mutable reference to the element at the given index
When index is out of range, it loops around
Sourcepub fn swap_internal(&mut self, a: usize, b: usize)
pub fn swap_internal(&mut self, a: usize, b: usize)
Swaps the two elements at the given indices a and b.
When a or b are out of range, they loop around
Sourcepub fn swap(&mut self, index: usize, elem: T) -> T
pub fn swap(&mut self, index: usize, elem: T) -> T
Swaps the element at the given index with the specifiied new one.
When a or b are out of range, they loop around
Sourcepub fn iter_circular<'s>(&'s self) -> IterCircular<'s, T>
pub fn iter_circular<'s>(&'s self) -> IterCircular<'s, T>
Returns an iterator over the buffer looping around at the end. This creates a never ending iterator
Sourcepub fn iter<'s>(&'s self) -> Iter<'s, T>
pub fn iter<'s>(&'s self) -> Iter<'s, T>
Returns an iterator over the buffer without looping around.
Sourcepub unsafe fn from_raw_parts(list: Box<[T]>, first: usize) -> Self
pub unsafe fn from_raw_parts(list: Box<[T]>, first: usize) -> Self
Constructs the structure from its raw components
§Unsafety
This function is unsafe as there is no guarantee that first < list.len(), nor whether list is non-empty.
Sourcepub fn into_raw_parts(self) -> (Box<[T]>, usize)
pub fn into_raw_parts(self) -> (Box<[T]>, usize)
Deconstructs the structure into its raw components
Trait Implementations§
Source§impl<T: Clone> Clone for CircularBuffer<T>
impl<T: Clone> Clone for CircularBuffer<T>
Source§fn clone(&self) -> CircularBuffer<T>
fn clone(&self) -> CircularBuffer<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more