pub trait RateLimiter: Send + Sync {
// Required methods
fn check(&self, key: &str) -> bool;
fn peek(&self, key: &str) -> u32;
fn reset(&self, key: &str);
}Expand description
Trait for rate limiters. Implementations decide whether a request
from key (typically a client ID or IP) should be allowed.
Required Methods§
Sourcefn check(&self, key: &str) -> bool
fn check(&self, key: &str) -> bool
Check if a request is allowed. Consumes one token if allowed.
Returns true if allowed, false if rate-limited.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".