struct TokenBucket {
tokens: f64,
last_refill: Instant,
max_tokens: f64,
refill_rate: f64,
}Expand description
A token bucket for a single client IP.
Fields§
§tokens: f64§last_refill: Instant§max_tokens: f64§refill_rate: f64Implementations§
Source§impl TokenBucket
impl TokenBucket
fn new(burst_size: u32, refill_rate: u32) -> Self
Sourcefn try_consume(&mut self) -> bool
fn try_consume(&mut self) -> bool
Attempts to consume a token. Returns true if allowed, false if rate limited.
Sourcefn retry_after(&self) -> u64
fn retry_after(&self) -> u64
Returns the estimated seconds until a token is available.
Auto Trait Implementations§
impl Freeze for TokenBucket
impl RefUnwindSafe for TokenBucket
impl Send for TokenBucket
impl Sync for TokenBucket
impl Unpin for TokenBucket
impl UnwindSafe for TokenBucket
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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