pub struct ActionTracker { /* private fields */ }Expand description
Tracks actions in a sliding window for rate limiting
Implementations§
Source§impl ActionTracker
impl ActionTracker
Sourcepub fn with_window(window_secs: u64) -> Self
pub fn with_window(window_secs: u64) -> Self
Create a new action tracker with custom window size
Sourcepub fn is_rate_limited(&self, max_actions: u32) -> bool
pub fn is_rate_limited(&self, max_actions: u32) -> bool
Check if the action count exceeds the limit
Sourcepub fn try_record(&self, max_actions: u32) -> bool
pub fn try_record(&self, max_actions: u32) -> bool
Try to record an action, returning false if rate limited
Sourcepub fn window_duration(&self) -> Duration
pub fn window_duration(&self) -> Duration
Get the window duration
Trait Implementations§
Source§impl Clone for ActionTracker
impl Clone for ActionTracker
Source§impl Debug for ActionTracker
impl Debug for ActionTracker
Auto Trait Implementations§
impl !Freeze for ActionTracker
impl !RefUnwindSafe for ActionTracker
impl Send for ActionTracker
impl Sync for ActionTracker
impl Unpin for ActionTracker
impl UnsafeUnpin for ActionTracker
impl UnwindSafe for ActionTracker
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