Struct fixed_circular_buffer::CircularBuffer
[−]
[src]
pub struct CircularBuffer<T, L = Box<[T]>> { /* fields omitted */ }
Fixed size circular/cyclic/ring buffer
Almost a FIFO (first in, first out) queue. · It cannot represent an empty buffer. · The queue is always filled (Cannot dequeue without queueing).
When constructed, the internal list
must not be empty.
Methods
impl<T, L> CircularBuffer<T, L>
[src]
pub unsafe fn from_raw_parts(list: L, first: usize) -> Self
[src]
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.
pub fn into_raw_parts(self) -> (L, usize)
[src]
Deconstructs the structure into its raw components
impl<T, L> CircularBuffer<T, L> where
L: Deref<Target = [T]>,
[src]
L: Deref<Target = [T]>,
pub fn len(&self) -> usize
[src]
Returns the number of elements (before starting to loop around).
pub fn iter_circular<'s>(&'s self) -> IterCircular<'s, T>
[src]
Returns an iterator over the buffer looping around at the end.
This iterator is initially iterating from the most recently queued element to the oldest, and then looping around (relative to queue
).
This creates a never ending iterator
pub fn iter<'s>(&'s self) -> Iter<'s, T>
[src]
Returns an iterator over the buffer without looping around.
Iterates from the most recently queued element to the oldest queued element (relative to queue
).
pub fn internal_index(&self, index: usize) -> usize
[src]
pub fn get(&self, index: usize) -> &T
[src]
Returns a reference to the element at the given index.
Smaller indices are more recently queued elements (relative to queue
) (0 is the newest).
When index
is out of range, it loops around.
pub fn internal_index_reversed(&self, index: usize) -> usize
[src]
impl<T, L> CircularBuffer<T, L> where
L: DerefMut<Target = [T]>,
[src]
L: DerefMut<Target = [T]>,
pub fn swap(&mut self, elem: T) -> T
[src]
Swaps the most recently queued element.
pub fn queue(&mut self, elem: T) -> T
[src]
Enqueues (push at beginning) the given element at the beginning of the buffer. Dequeues (pop at end) the last element and returns it.
pub fn set_first(&mut self, index: usize)
[src]
Sets the offset for the first element, relative to the currently first element.
Smaller indices are more recently queued elements (relative to queue
) (0 is the newest).
When index
is out of range, it loops around.
pub fn get_mut(&mut self, index: usize) -> &mut T
[src]
Returns a mutable reference to the element at the given index.
Smaller indices are more recently queued elements (relative to queue
) (0 is the newest).
When index
is out of range, it loops around.
pub fn swap_internal(&mut self, a: usize, b: usize)
[src]
Swaps the two elements at the given indices a
and b
.
Smaller indices are more recently queued elements (relative to queue
) (0 is the newest).
When a
or b
are out of range, they loop around.
pub fn swap_at(&mut self, index: usize, elem: T) -> T
[src]
Swaps the element at the given index with the specifiied new one.
When a
or b
are out of range, they loop around.
pub fn queue_reversed(&mut self, elem: T) -> T
[src]
Trait Implementations
impl<T: Copy, L: Copy> Copy for CircularBuffer<T, L>
[src]
impl<T: Clone, L: Clone> Clone for CircularBuffer<T, L>
[src]
fn clone(&self) -> CircularBuffer<T, L>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: Debug, L: Debug> Debug for CircularBuffer<T, L>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T: Eq, L: Eq> Eq for CircularBuffer<T, L>
[src]
impl<T: PartialEq, L: PartialEq> PartialEq for CircularBuffer<T, L>
[src]
fn eq(&self, __arg_0: &CircularBuffer<T, L>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &CircularBuffer<T, L>) -> bool
[src]
This method tests for !=
.
impl<T: Hash, L: Hash> Hash for CircularBuffer<T, L>
[src]
fn hash<__HTL: Hasher>(&self, __arg_0: &mut __HTL)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T> From<Vec<T>> for CircularBuffer<T>
[src]
fn from(vec: Vec<T>) -> Self
[src]
Constructs an already filled circular buffer from the elements in a vec. The first element in the Vec will be interpreted as the most reecntly queued element, and the last element as the oldest.
impl<T, L> From<L> for CircularBuffer<T, L> where
L: Deref<Target = [T]>,
[src]
L: Deref<Target = [T]>,
impl<T> FromIterator<T> for CircularBuffer<T>
[src]
fn from_iter<I>(i: I) -> Self where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
Creates a value from an iterator. Read more