pub struct RateLimiters { /* private fields */ }Expand description
A registry of per-credential token buckets. Lookups take a short, non-async
lock and never hold it across an .await, so a std::sync::Mutex is correct
here.
Implementations§
Source§impl RateLimiters
impl RateLimiters
Sourcepub fn new(config: RateLimitConfig) -> Self
pub fn new(config: RateLimitConfig) -> Self
Build an empty registry with the given config.
Sourcepub fn allow(&self, key: &str) -> bool
pub fn allow(&self, key: &str) -> bool
Admit one op for key (the sniffed credential), spending a token. Returns
true if a token was available, false if the bucket is empty (the op
should be rejected with a wire ERROR). Always true when limiting is off.
§Panics
If the bucket mutex is poisoned — which means another thread panicked while holding it, and the limiter’s accounting is no longer trustworthy.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for RateLimiters
impl RefUnwindSafe for RateLimiters
impl Send for RateLimiters
impl Sync for RateLimiters
impl Unpin for RateLimiters
impl UnsafeUnpin for RateLimiters
impl UnwindSafe for RateLimiters
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