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 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> 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§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,
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Arc<>