pub struct RateLimiter { /* private fields */ }Expand description
Rate limiter using token bucket algorithm.
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(config: RateLimitConfig) -> Self
pub fn new(config: RateLimitConfig) -> Self
Create a new rate limiter.
Sourcepub fn check(&self, client_id: Option<&str>) -> bool
pub fn check(&self, client_id: Option<&str>) -> bool
Check if a request is allowed.
Returns true if allowed, false if rate limited.
Sourcepub fn client_bucket_count(&self) -> usize
pub fn client_bucket_count(&self) -> usize
Get the current number of tracked client buckets.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for RateLimiter
impl !RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnsafeUnpin for RateLimiter
impl UnwindSafe for RateLimiter
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