Trait ringbuffer::RingBufferExt
source · pub unsafe trait RingBufferExt<T>: RingBuffer<T> + RingBufferRead<T> + RingBufferWrite<T> + Index<isize, Output = T> + IndexMut<isize> + FromIterator<T> {
Show 17 methods
fn fill_with<F: FnMut() -> T>(&mut self, f: F);
fn clear(&mut self);
fn get(&self, index: isize) -> Option<&T>;
fn get_absolute(&self, index: usize) -> Option<&T>;
fn get_absolute_mut(&mut self, index: usize) -> Option<&mut T>;
fn fill_default(&mut self)
where
T: Default,
{ ... }
fn fill(&mut self, value: T)
where
T: Clone,
{ ... }
fn get_mut(&mut self, index: isize) -> Option<&mut T> { ... }
fn peek(&self) -> Option<&T> { ... }
fn front(&self) -> Option<&T> { ... }
fn front_mut(&mut self) -> Option<&mut T> { ... }
fn back(&self) -> Option<&T> { ... }
fn back_mut(&mut self) -> Option<&mut T> { ... }
fn iter_mut(&mut self) -> RingBufferMutIterator<'_, T, Self> { ... }
fn iter(&self) -> RingBufferIterator<'_, T, Self> { ... }
fn to_vec(&self) -> Vec<T>
where
T: Clone,
{ ... }
fn contains(&self, elem: &T) -> bool
where
T: PartialEq,
{ ... }
}
Expand description
Defines behaviour for ringbuffers which allow them to be used as a general purpose buffer. With this trait, arbitrary access of elements in the buffer is possible.
Safety
Implementing this implies that the ringbuffer upholds some safety
guarantees, such as returning a different value from get_mut
any
for every different index passed in. See the exact requirements
in the safety comment on the next function of the mutable Iterator
implementation, since these safety guarantees are necessary for
[iter_mut
] to work
Required Methods§
sourcefn fill_with<F: FnMut() -> T>(&mut self, f: F)
fn fill_with<F: FnMut() -> T>(&mut self, f: F)
Sets every element in the ringbuffer to the value returned by f.
sourcefn clear(&mut self)
fn clear(&mut self)
Empties the buffer entirely. Sets the length to 0 but keeps the capacity allocated.
sourcefn get(&self, index: isize) -> Option<&T>
fn get(&self, index: isize) -> Option<&T>
Gets a value relative to the current index. 0 is the next index to be written to with push. -1 and down are the last elements pushed and 0 and up are the items that were pushed the longest ago.
sourcefn get_absolute(&self, index: usize) -> Option<&T>
fn get_absolute(&self, index: usize) -> Option<&T>
Gets a value relative to the start of the array (rarely useful, usually you want Self::get
)
sourcefn get_absolute_mut(&mut self, index: usize) -> Option<&mut T>
fn get_absolute_mut(&mut self, index: usize) -> Option<&mut T>
Gets a value mutably relative to the start of the array (rarely useful, usually you want Self::get_mut
)
Provided Methods§
sourcefn fill_default(&mut self)where
T: Default,
fn fill_default(&mut self)where
T: Default,
Sets every element in the ringbuffer to it’s default value
sourcefn get_mut(&mut self, index: isize) -> Option<&mut T>
fn get_mut(&mut self, index: isize) -> Option<&mut T>
Gets a value relative to the current index mutably. 0 is the next index to be written to with push. -1 and down are the last elements pushed and 0 and up are the items that were pushed the longest ago.
sourcefn peek(&self) -> Option<&T>
fn peek(&self) -> Option<&T>
Returns the value at the current index.
This is the value that will be overwritten by the next push and also the value pushed
the longest ago. (alias of Self::front
)
sourcefn front(&self) -> Option<&T>
fn front(&self) -> Option<&T>
Returns the value at the front of the queue. This is the value that will be overwritten by the next push and also the value pushed the longest ago. (alias of peek)
sourcefn front_mut(&mut self) -> Option<&mut T>
fn front_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the value at the back of the queue. This is the value that will be overwritten by the next push. (alias of peek)
sourcefn back(&self) -> Option<&T>
fn back(&self) -> Option<&T>
Returns the value at the back of the queue. This is the item that was pushed most recently.
sourcefn back_mut(&mut self) -> Option<&mut T>
fn back_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the value at the back of the queue. This is the item that was pushed most recently.
sourcefn iter_mut(&mut self) -> RingBufferMutIterator<'_, T, Self>
fn iter_mut(&mut self) -> RingBufferMutIterator<'_, T, Self>
Creates a mutable iterator over the buffer starting from the item pushed the longest ago, and ending at the element most recently pushed.
sourcefn iter(&self) -> RingBufferIterator<'_, T, Self>
fn iter(&self) -> RingBufferIterator<'_, T, Self>
Creates an iterator over the buffer starting from the item pushed the longest ago, and ending at the element most recently pushed.