pub struct HzWindow { /* private fields */ }Expand description
A trailing window of arrival instants, for astrs topic hz’s rate math.
Pure and independent of any socket, so the rate computation is tested without a live cluster.
Implementations§
Source§impl HzWindow
impl HzWindow
Sourcepub fn record(&mut self, now: Instant)
pub fn record(&mut self, now: Instant)
Records one arrival at now, dropping anything that has aged out.
Sourcepub fn rate_per_sec(&self, now: Instant) -> Option<f64>
pub fn rate_per_sec(&self, now: Instant) -> Option<f64>
The observed rate, in messages per second, as of now.
None before any arrival, or while the observed span is too short
to divide by without an inflated result — the span used is the
window itself once at least two arrivals separate by less than it,
and the actual oldest-to-now span otherwise, which is what keeps
the very first arrival from reading as “infinite Hz”.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HzWindow
impl RefUnwindSafe for HzWindow
impl Send for HzWindow
impl Sync for HzWindow
impl Unpin for HzWindow
impl UnsafeUnpin for HzWindow
impl UnwindSafe for HzWindow
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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 more