pub struct BaselineStore<T> { /* private fields */ }Expand description
A fixed-capacity ring buffer of baselines keyed by tick.
Implementations§
Source§impl<T> BaselineStore<T>
impl<T> BaselineStore<T>
Sourcepub fn new(capacity: NonZeroUsize) -> Self
pub fn new(capacity: NonZeroUsize) -> Self
Creates a new baseline store with the given capacity.
Sourcepub fn insert(
&mut self,
tick: SnapshotTick,
value: T,
) -> Result<(), BaselineError>
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.
Sourcepub fn get(&self, tick: SnapshotTick) -> Option<&T>
pub fn get(&self, tick: SnapshotTick) -> Option<&T>
Returns the baseline for an exact tick, if present.
Sourcepub fn latest_at_or_before(
&self,
tick: SnapshotTick,
) -> Option<(SnapshotTick, &T)>
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.
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = (SnapshotTick, &T)>
pub fn iter(&self) -> impl DoubleEndedIterator<Item = (SnapshotTick, &T)>
Returns an iterator from oldest to newest.
Trait Implementations§
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> 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