Skip to main content

BaselineStore

Struct BaselineStore 

Source
pub struct BaselineStore<T> { /* private fields */ }
Expand description

A fixed-capacity ring buffer of baselines keyed by tick.

Implementations§

Source§

impl<T> BaselineStore<T>

Source

pub fn new(capacity: NonZeroUsize) -> Self

Creates a new baseline store with the given capacity.

Source

pub fn capacity(&self) -> usize

Returns the capacity of the store.

Source

pub fn len(&self) -> usize

Returns the number of entries stored.

Source

pub fn is_empty(&self) -> bool

Returns true if the store is empty.

Source

pub fn insert( &mut self, tick: SnapshotTick, value: T, ) -> Result<(), BaselineError>

Inserts a new baseline at the given tick.

Ticks must be strictly increasing.

When the store is full, this overwrites the oldest entry and advances the head, making the inserted tick the newest entry immediately.

Source

pub fn get(&self, tick: SnapshotTick) -> Option<&T>

Returns the baseline for an exact tick, if present.

Source

pub fn latest_at_or_before( &self, tick: SnapshotTick, ) -> Option<(SnapshotTick, &T)>

Returns the latest baseline at or before the given tick.

This performs an O(capacity) scan and is intended for small windows.

Source

pub fn iter(&self) -> impl DoubleEndedIterator<Item = (SnapshotTick, &T)>

Returns an iterator from oldest to newest.

Trait Implementations§

Source§

impl<T: Debug> Debug for BaselineStore<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for BaselineStore<T>

§

impl<T> RefUnwindSafe for BaselineStore<T>
where T: RefUnwindSafe,

§

impl<T> Send for BaselineStore<T>
where T: Send,

§

impl<T> Sync for BaselineStore<T>
where T: Sync,

§

impl<T> Unpin for BaselineStore<T>
where T: Unpin,

§

impl<T> UnwindSafe for BaselineStore<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.