Struct matrix_sdk_base::ring_buffer::RingBuffer
source · pub struct RingBuffer<T> { /* private fields */ }
Expand description
A simple fixed-size ring buffer implementation.
A size is provided on creation, and the ring buffer reserves that much space, and never reallocates.
Implementations§
source§impl<T> RingBuffer<T>
impl<T> RingBuffer<T>
sourcepub fn new(size: usize) -> RingBuffer<T>
pub fn new(size: usize) -> RingBuffer<T>
Create a ring buffer with the supplied capacity, reserving it so we never need to reallocate.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of items that are stored in this ring buffer.
This is the dynamic size indicating how many items are held in the buffer, not the fixed capacity.
sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Provides a reference to the element at the given index.
Element at index zero is the “front” i.e. one that will be returned if we call pop().
sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes the first element and returns it, or None if the ring buffer is empty.
sourcepub fn remove(&mut self, index: usize) -> Option<T>
pub fn remove(&mut self, index: usize) -> Option<T>
Removes and returns one specific element at index
if it exists,
otherwise it returns None
.
sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Returns an iterator that provides elements in front-to-back order, i.e. the same order you would get if you repeatedly called pop().
sourcepub fn drain<R>(&mut self, range: R) -> Drain<'_, T>where
R: RangeBounds<usize>,
pub fn drain<R>(&mut self, range: R) -> Drain<'_, T>where
R: RangeBounds<usize>,
Returns an iterator that drains its items.
Trait Implementations§
source§impl<T> Clone for RingBuffer<T>where
T: Clone,
impl<T> Clone for RingBuffer<T>where
T: Clone,
source§fn clone(&self) -> RingBuffer<T>
fn clone(&self) -> RingBuffer<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T> Debug for RingBuffer<T>where
T: Debug,
impl<T> Debug for RingBuffer<T>where
T: Debug,
source§impl<T> Default for RingBuffer<T>
impl<T> Default for RingBuffer<T>
source§fn default() -> RingBuffer<T>
fn default() -> RingBuffer<T>
source§impl<'de, T> Deserialize<'de> for RingBuffer<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for RingBuffer<T>where
T: Deserialize<'de>,
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<RingBuffer<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<RingBuffer<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl<U> Extend<U> for RingBuffer<U>
impl<U> Extend<U> for RingBuffer<U>
source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = U>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = U>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<T> PartialEq for RingBuffer<T>where
T: PartialEq,
impl<T> PartialEq for RingBuffer<T>where
T: PartialEq,
source§fn eq(&self, other: &RingBuffer<T>) -> bool
fn eq(&self, other: &RingBuffer<T>) -> bool
self
and other
values to be equal, and is used
by ==
.