pub struct RateLimiter { /* private fields */ }Expand description
Concurrent per-key rate limiter.
Each API key ID gets its own [TokenBucket]. Buckets are created
on first access and cleaned up when stale.
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(rpm: u32) -> Self
pub fn new(rpm: u32) -> Self
Create a new rate limiter with the given per-key requests-per-minute limit.
The refill window defaults to 60 seconds unless AA_RATE_LIMIT_WINDOW_SECS
is set in the environment.
Sourcepub fn new_with_window(rpm: u32, window_secs: u64) -> Self
pub fn new_with_window(rpm: u32, window_secs: u64) -> Self
Create a new rate limiter with an explicit refill window.
Intended for tests that need a short window without setting an env-var.
Auto Trait Implementations§
impl !RefUnwindSafe for RateLimiter
impl Freeze 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