pub struct RingBuffer<T> { /* private fields */ }Expand description
Fixed-capacity FIFO ring buffer; pushing past capacity drops the oldest item.
Implementations§
Source§impl<T> RingBuffer<T>
impl<T> RingBuffer<T>
Sourcepub fn push(&mut self, item: T) -> Option<T>
pub fn push(&mut self, item: T) -> Option<T>
Append an item, returning the evicted oldest item if full.
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &T> + ExactSizeIterator
Iterate oldest → newest.
Trait Implementations§
Source§impl<T: Clone> Clone for RingBuffer<T>
impl<T: Clone> Clone for RingBuffer<T>
Source§impl<T: Debug> Debug for RingBuffer<T>
impl<T: Debug> Debug for RingBuffer<T>
Source§impl<T> Extend<T> for RingBuffer<T>
impl<T> Extend<T> for RingBuffer<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<T: PartialEq> PartialEq for RingBuffer<T>
impl<T: PartialEq> PartialEq for RingBuffer<T>
impl<T: PartialEq> StructuralPartialEq for RingBuffer<T>
Auto Trait Implementations§
impl<T> Forget for RingBuffer<T>
impl<T> Freeze for RingBuffer<T>
impl<T> RefUnwindSafe for RingBuffer<T>where
VecDeque<T>: RefUnwindSafe,
impl<T> Send for RingBuffer<T>
impl<T> Sync for RingBuffer<T>
impl<T> Unpin for RingBuffer<T>
impl<T> UnsafeUnpin for RingBuffer<T>where
VecDeque<T>: UnsafeUnpin,
impl<T> UnwindSafe for RingBuffer<T>where
VecDeque<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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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