Struct matrix_sdk_common::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: NonZeroUsize) -> Self
pub fn new(size: NonZeroUsize) -> Self
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> Clone for RingBuffer<T>
impl<T: Clone> Clone for RingBuffer<T>
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> Debug for RingBuffer<T>
impl<T: Debug> Debug for 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<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<U> Extend<U> for RingBuffer<U>
impl<U> Extend<U> for RingBuffer<U>
source§fn extend<T: IntoIterator<Item = U>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = U>>(&mut self, iter: T)
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> PartialEq for RingBuffer<T>
impl<T: PartialEq> PartialEq for RingBuffer<T>
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 ==
.source§impl<T> Serialize for RingBuffer<T>where
T: Serialize,
impl<T> Serialize for RingBuffer<T>where
T: Serialize,
impl<T> StructuralPartialEq for RingBuffer<T>
Auto Trait Implementations§
impl<T> Freeze for RingBuffer<T>
impl<T> RefUnwindSafe for RingBuffer<T>where
T: RefUnwindSafe,
impl<T> Send for RingBuffer<T>where
T: Send,
impl<T> Sync for RingBuffer<T>where
T: Sync,
impl<T> Unpin for RingBuffer<T>where
T: Unpin,
impl<T> UnwindSafe for RingBuffer<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)