Struct rbuf::RingBuf [−][src]
pub struct RingBuf<T> { /* fields omitted */ }
Expand description
A ring buffer for arbitrary but default-initializable data.
The ring buffer is always “full”, but may only contain “default”
representations of the given type if nothing else has been inserted.
There is no concept of a removing elements, only overwriting them
with the default. Gaps or non-existent elements can be represented
by having an element type Option<T>
.
One implication of the above is that iteration will always yield as many elements as the ring buffer’s size.
Indexing into the ring buffer using bracket notation works in such a
way that an index of 0
always accesses the least recently added
element and an index of self.len() - 1
the most recently added
one. Furthermore, indexes wrap around at the ring buffer’s end,
meaning that an index of value self.len()
would access the same
element as index 0
.
Implementations
Create a new RingBuf
of a fixed length as provided.
len
must be greater than zero.
Pop the most recently added element from the ring buffer.
This operation will remove the ring buffer’s most recently added
element and replace it with the default value of T
. The formerly
second most recently added element will be the ring buffer’s new
“front”.
Convert the RingBuf
into a boxed slice of its contents.
Create a new RingBuf
with data from a Vec
.
Note that the vector’s first element is considered the oldest one,
which means that the first read will access it and pushed data
will overwrite it first.
Note furthermore that the provided Vec
is required to contain at
least a single element.
Retrieve the current “front” element, i.e., the element that got inserted most recently.
Retrieve the current “front” element, i.e., the element that got inserted most recently.
Retrieve the current “front” index, i.e., the index of the element that got inserted most recently.
Note that this index only has real relevance when accessing the
underlying slice using deref
. In particular, the index returned
by this method should not be confused with those as expected by
our Index
implementation (as accessible through bracket syntax).
Retrieve the current “back” element, i.e., the element that got inserted the furthest in the past.
Retrieve the current “back” element, i.e., the element that got inserted the furthest in the past.
Retrieve the current “back” index, i.e., the index of the element that got inserted the furthest in the past.
Note that this index only has real relevance when accessing the
underlying slice using deref
. In particular, the index returned
by this method should not be confused with those as expected by
our Index
implementation (as accessible through bracket syntax).
Push an element into the ring buffer.
This operation will evict the ring buffer’s least recently added element (i.e., the element at the back) and replace it with the provided one. The newly pushed element will be considered the ring buffer’s new “front”.
Retrieve an iterator over the elements of the ring buffer.
pub fn iter_mut(&mut self) -> RingIterMut<'_, T>ⓘNotable traits for RingIterMut<'b, T>impl<'b, T> Iterator for RingIterMut<'b, T> type Item = &'b mut T;
pub fn iter_mut(&mut self) -> RingIterMut<'_, T>ⓘNotable traits for RingIterMut<'b, T>impl<'b, T> Iterator for RingIterMut<'b, T> type Item = &'b mut T;
impl<'b, T> Iterator for RingIterMut<'b, T> type Item = &'b mut T;
Retrieve a mutating iterator over the elements of the ring buffer.
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for RingBuf<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for RingBuf<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more