pub struct HistoryBuffer<T> { /* private fields */ }
Expand description
A “history buffer”, similar to a write-only ring buffer of fixed length.
This buffer keeps a fixed number of elements. On write, the oldest element is overwritten. Thus, the buffer is useful to keep a history of values with some desired depth.
Implementations§
Source§impl<T> HistoryBuffer<T>
impl<T> HistoryBuffer<T>
Sourcepub fn most_recent(&self) -> Option<&T>
pub fn most_recent(&self) -> Option<&T>
Get the most recent value written to the buffer.
Sourcepub fn write(&mut self, val: T) -> Option<T>
pub fn write(&mut self, val: T) -> Option<T>
Write a new value into the buffer, if it overwrites an old value it is returned.
Sourcepub fn duration_since_last_measurement(&self) -> Option<Duration>
pub fn duration_since_last_measurement(&self) -> Option<Duration>
How long was it since the last measurement.
Sourcepub fn all_unsorted(&self) -> &[T]
pub fn all_unsorted(&self) -> &[T]
Get the entire buffer as unsorted.
Sourcepub fn all(&self) -> impl DoubleEndedIterator<Item = &T>
pub fn all(&self) -> impl DoubleEndedIterator<Item = &T>
Get the entire in chronological order, starting with the oldest element.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for HistoryBuffer<T>
impl<T> RefUnwindSafe for HistoryBuffer<T>where
T: RefUnwindSafe,
impl<T> Send for HistoryBuffer<T>where
T: Send,
impl<T> Sync for HistoryBuffer<T>where
T: Sync,
impl<T> Unpin for HistoryBuffer<T>where
T: Unpin,
impl<T> UnwindSafe for HistoryBuffer<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