pub struct KeyedRateLimiter { /* private fields */ }Expand description
Thread-safe sliding-window rate limiter keyed by an arbitrary string (source address, principal / agent id, etc.).
Implementations§
Source§impl KeyedRateLimiter
impl KeyedRateLimiter
Sourcepub fn new(config: RateLimitConfig) -> Self
pub fn new(config: RateLimitConfig) -> Self
Create a limiter with the given config.
Sourcepub fn config(&self) -> RateLimitConfig
pub fn config(&self) -> RateLimitConfig
Current configuration snapshot.
Sourcepub fn set_config(&self, config: RateLimitConfig)
pub fn set_config(&self, config: RateLimitConfig)
Replace the configuration at runtime.
Does not clear existing windows; the next check uses the new
thresholds against remaining timestamps.
Sourcepub fn check(&self, key: &str) -> bool
pub fn check(&self, key: &str) -> bool
Check whether an event for key is allowed.
On allow, records the event. On deny, does not record (so a denied flood does not permanently fill the window).
Returns true if allowed, false if rate-limited.
Sourcepub fn tracked_keys(&self) -> usize
pub fn tracked_keys(&self) -> usize
Number of tracked keys (for tests / metrics).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for KeyedRateLimiter
impl RefUnwindSafe for KeyedRateLimiter
impl Send for KeyedRateLimiter
impl Sync for KeyedRateLimiter
impl Unpin for KeyedRateLimiter
impl UnsafeUnpin for KeyedRateLimiter
impl UnwindSafe for KeyedRateLimiter
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> 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