pub struct RateWindow { /* private fields */ }Expand description
Sliding-bucket rate counter. Tracks per-second event counts in a
fixed ring of length window_secs. Provides observe_and_score
which:
- Increments the current second’s bucket.
- Computes the mean + std-dev across the ring.
- Returns z-score = (current_rate - mean) / std-dev when the window is fully populated AND std-dev > 0.
Implementations§
Source§impl RateWindow
impl RateWindow
pub fn new(window_secs: u64) -> Self
Sourcepub fn observe_and_score(&mut self, now: Instant) -> Option<SpikeScore>
pub fn observe_and_score(&mut self, now: Instant) -> Option<SpikeScore>
Bump the current bucket by one event and return a SpikeScore when the window has accumulated enough data to be meaningful (full window AND non-zero std-dev).
Trait Implementations§
Source§impl Clone for RateWindow
impl Clone for RateWindow
Source§fn clone(&self) -> RateWindow
fn clone(&self) -> RateWindow
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for RateWindow
impl RefUnwindSafe for RateWindow
impl Send for RateWindow
impl Sync for RateWindow
impl Unpin for RateWindow
impl UnsafeUnpin for RateWindow
impl UnwindSafe for RateWindow
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
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