Struct HistoryBuffer

Source
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>

Source

pub fn new(max_size: usize) -> Self

Create a new buffer with a specified max depth.

Source

pub fn is_empty(&self) -> bool

Checks if the buffer is empty.

Source

pub fn is_full(&self) -> bool

Checks if the buffer is full, i.e. it has reached capacity.

Source

pub fn max_len(&self) -> usize

The maximum number of elements the buffer can hold.

Source

pub fn len(&self) -> usize

The number of elements currently in the buffer.

Source

pub fn clear(&mut self)

Clear all values in the buffer.

Source

pub fn most_recent(&self) -> Option<&T>

Get the most recent value written to the buffer.

Source

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.

Source

pub fn duration_since_last_measurement(&self) -> Option<Duration>

How long was it since the last measurement.

Source

pub fn all_unsorted(&self) -> &[T]

Get the entire buffer as unsorted.

Source

pub fn all(&self) -> impl DoubleEndedIterator<Item = &T>

Get the entire in chronological order, starting with the oldest element.

Trait Implementations§

Source§

impl<T> Debug for HistoryBuffer<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.