pub struct KeyedRateLimiter<K> { /* private fields */ }
Implementations§
source§impl<K> KeyedRateLimiter<K>
impl<K> KeyedRateLimiter<K>
sourcepub fn new(limit: u64, interval: Duration) -> Self
pub fn new(limit: u64, interval: Duration) -> Self
Create a keyed rate limiter with limit
count with a rate limit interval
sourcepub fn check_and_update(&self, key: K) -> bool
pub fn check_and_update(&self, key: K) -> bool
Check if the connection from the said key
is allowed to pass through the rate limiter.
When it is allowed, the rate limiter state is updated to reflect it has been
allowed. For a unique request, the caller should call it only once when it is allowed.
sourcepub fn retain_recent(&self)
pub fn retain_recent(&self)
retain only keys whose throttle start date is within the throttle interval. Otherwise drop them as inactive
Auto Trait Implementations§
impl<K> Freeze for KeyedRateLimiter<K>
impl<K> !RefUnwindSafe for KeyedRateLimiter<K>
impl<K> Send for KeyedRateLimiter<K>where
K: Send,
impl<K> Sync for KeyedRateLimiter<K>
impl<K> Unpin for KeyedRateLimiter<K>
impl<K> UnwindSafe for KeyedRateLimiter<K>where
K: UnwindSafe,
Blanket Implementations§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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