Struct RateDetector
pub struct RateDetector { /* private fields */ }Expand description
Fires when at least count matching events occur within window.
On each check():
- If
eventisSomeand the filter accepts it, push the current timestamp. - Expire timestamps older than
window. - Return
trueif the remaining count >= threshold.
Implementations§
§impl RateDetector
impl RateDetector
pub fn new(
filter: Arc<dyn Fn(&SessionEvent) -> bool + Send + Sync>,
count: u32,
window: Duration,
) -> RateDetector
pub fn new( filter: Arc<dyn Fn(&SessionEvent) -> bool + Send + Sync>, count: u32, window: Duration, ) -> RateDetector
Create a new rate detector.
filter: predicate to select which events count.count: number of matching events required.window: sliding time window.
Trait Implementations§
§impl PatternDetector for RateDetector
impl PatternDetector for RateDetector
Auto Trait Implementations§
impl !Freeze for RateDetector
impl !RefUnwindSafe for RateDetector
impl Send for RateDetector
impl Sync for RateDetector
impl Unpin for RateDetector
impl !UnwindSafe for RateDetector
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