Struct fixed_circular_buffer::CircularBuffer
[−]
[src]
pub struct CircularBuffer<T> { /* fields omitted */ }
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.
Methods
impl<T> CircularBuffer<T>
[src]
fn len(&self) -> usize
Returns the number of elements (before starting to loop around).
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
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
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
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
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
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
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
fn iter<'s>(&'s self) -> Iter<'s, T>
Returns an iterator over the buffer without looping around.
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.
fn into_raw_parts(self) -> (Box<[T]>, usize)
Deconstructs the structure into its raw components
Trait Implementations
impl<T: Clone> Clone for CircularBuffer<T>
[src]
fn clone(&self) -> CircularBuffer<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: Eq> Eq for CircularBuffer<T>
[src]
impl<T: PartialEq> PartialEq for CircularBuffer<T>
[src]
fn eq(&self, __arg_0: &CircularBuffer<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &CircularBuffer<T>) -> bool
This method tests for !=
.
impl<T: Hash> Hash for CircularBuffer<T>
[src]
fn hash<__HT: Hasher>(&self, __arg_0: &mut __HT)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T> From<Vec<T>> for CircularBuffer<T>
[src]
impl<T> From<Box<[T]>> for CircularBuffer<T>
[src]
impl<T> FromIterator<T> for CircularBuffer<T>
[src]
fn from_iter<I>(i: I) -> Self where
I: IntoIterator<Item = T>,
I: IntoIterator<Item = T>,
Creates a value from an iterator. Read more