pub struct TimestampedRingBuffer<T: Copy> { /* private fields */ }Expand description
An SPSC ring buffer that stores TimestampedValue entries and exposes
time-range queries and throughput estimation.
Internally backed by a StatisticsWindow<f64> for the values and a
separate Vec-based circular buffer for the full TimestampedValue records.
Implementations§
Source§impl<T: Copy> TimestampedRingBuffer<T>
impl<T: Copy> TimestampedRingBuffer<T>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new buffer with the given capacity.
Panics if capacity == 0.
Sourcepub fn push_now(&mut self, value: T, time_ns: u64)
pub fn push_now(&mut self, value: T, time_ns: u64)
Push a new (value, timestamp_ns) pair.
If the buffer is full the oldest entry is evicted.
Sourcepub fn iter_ordered(&self) -> impl Iterator<Item = TimestampedValue<T>> + '_
pub fn iter_ordered(&self) -> impl Iterator<Item = TimestampedValue<T>> + '_
Iterate over all stored entries in insertion order (oldest first).
Sourcepub fn rate_per_sec(&self) -> f64
pub fn rate_per_sec(&self) -> f64
Estimate throughput as events per second over the entire stored window.
Returns 0.0 when fewer than 2 entries are stored or the time span is zero.
Sourcepub fn values_in_range(&self, start_ns: u64, end_ns: u64) -> Vec<T>
pub fn values_in_range(&self, start_ns: u64, end_ns: u64) -> Vec<T>
Return all values whose timestamps fall in [start_ns, end_ns]
(inclusive on both ends).
Sourcepub fn oldest_timestamp(&self) -> Option<u64>
pub fn oldest_timestamp(&self) -> Option<u64>
The timestamp of the oldest retained entry.
Sourcepub fn newest_timestamp(&self) -> Option<u64>
pub fn newest_timestamp(&self) -> Option<u64>
The timestamp of the most-recently added entry.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for TimestampedRingBuffer<T>
impl<T> RefUnwindSafe for TimestampedRingBuffer<T>
impl<T> Send for TimestampedRingBuffer<T>
impl<T> Sync for TimestampedRingBuffer<T>
impl<T> Unpin for TimestampedRingBuffer<T>
impl<T> UnsafeUnpin for TimestampedRingBuffer<T>
impl<T> UnwindSafe for TimestampedRingBuffer<T>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.