Struct matrix_sdk::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: NonZero<usize>) -> RingBuffer<T>
pub fn new(size: NonZero<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 iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
Returns a mutable 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<'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 ==
.source§impl<T> Serialize for RingBuffer<T>where
T: Serialize,
impl<T> Serialize for RingBuffer<T>where
T: Serialize,
source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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
)source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more