Struct rate_limiter::token_bucket::TokenBucket
source · pub struct TokenBucket {
rate_per_second: usize,
available: usize,
requested: usize,
last_update: Instant,
}
Expand description
Implementation of the Token Bucket
algorithm for the purpose of rate-limiting access to some abstract resource.
Fields§
§rate_per_second: usize
§available: usize
§requested: usize
§last_update: Instant
Implementations§
source§impl TokenBucket
impl TokenBucket
sourcepub fn new(rate_per_second: usize) -> Self
pub fn new(rate_per_second: usize) -> Self
Constructs a instance of TokenBucket with given target rate-per-second.
fn calculate_delay(&self) -> Duration
fn update_units(&mut self, now: Instant) -> usize
sourcepub fn rate_limit(&mut self, requested: usize, now: Instant) -> Option<Duration>
pub fn rate_limit(&mut self, requested: usize, now: Instant) -> Option<Duration>
Calculates Duration by which we should delay the next call to some governed resource in order to satisfy configured rate limit.
fn token_limit(&self) -> usize
Trait Implementations§
source§impl Clone for TokenBucket
impl Clone for TokenBucket
source§fn clone(&self) -> TokenBucket
fn clone(&self) -> TokenBucket
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
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