pub struct DataSeries<T: Clone> { /* private fields */ }Expand description
A fixed-capacity ring buffer that holds a sliding window of data items.
When the buffer is full, pushing a new item overwrites the oldest entry. Items are always presented in chronological order (oldest first).
Implementations§
Source§impl<T: Clone> DataSeries<T>
impl<T: Clone> DataSeries<T>
Sourcepub fn push(&mut self, item: T)
pub fn push(&mut self, item: T)
Pushes an item into the ring buffer in O(1) time.
If the buffer is already at capacity the oldest item is overwritten.
Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Returns a reference to the item at index where 0 is the oldest item.
Returns None if index is out of bounds.
Sourcepub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &T>
Returns an iterator that yields references from oldest to newest.
Trait Implementations§
Source§impl<T: Clone + Clone> Clone for DataSeries<T>
impl<T: Clone + Clone> Clone for DataSeries<T>
Source§fn clone(&self) -> DataSeries<T>
fn clone(&self) -> DataSeries<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for DataSeries<T>
impl<T> RefUnwindSafe for DataSeries<T>where
T: RefUnwindSafe,
impl<T> Send for DataSeries<T>where
T: Send,
impl<T> Sync for DataSeries<T>where
T: Sync,
impl<T> Unpin for DataSeries<T>where
T: Unpin,
impl<T> UnsafeUnpin for DataSeries<T>
impl<T> UnwindSafe for DataSeries<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
Mutably borrows from an owned value. Read more