Struct dbs_utils::rate_limiter::TokenBucket
source · [−]pub struct TokenBucket { /* private fields */ }Expand description
TokenBucket provides a lower level interface to rate limiting with a configurable capacity, refill-rate and initial burst.
Implementations
sourceimpl TokenBucket
impl TokenBucket
sourcepub fn new(size: u64, one_time_burst: u64, complete_refill_time_ms: u64) -> Self
pub fn new(size: u64, one_time_burst: u64, complete_refill_time_ms: u64) -> Self
Creates a TokenBucket wrapped in an Option.
TokenBucket created is of size total capacity and takes complete_refill_time_ms
milliseconds to go from zero tokens to total capacity. The one_time_burst is initial
extra credit on top of total capacity, that does not replenish and which can be used
for an initial burst of data.
If the size or the complete refill time are zero, then None is returned.
sourcepub fn reduce(&mut self, tokens: u64) -> BucketReduction
pub fn reduce(&mut self, tokens: u64) -> BucketReduction
Attempts to consume tokens from the bucket and returns whether the action succeeded.
sourcepub fn force_replenish(&mut self, tokens: u64)
pub fn force_replenish(&mut self, tokens: u64)
“Manually” adds tokens to bucket.
sourcepub fn one_time_burst(&self) -> u64
pub fn one_time_burst(&self) -> u64
Returns the remaining one time burst budget.
sourcepub fn refill_time_ms(&self) -> u64
pub fn refill_time_ms(&self) -> u64
Returns the time in milliseconds required to to completely fill the bucket.
sourcepub fn budget(&self) -> u64
pub fn budget(&self) -> u64
Returns the current budget (one time burst allowance notwithstanding).
sourcepub fn initial_one_time_burst(&self) -> u64
pub fn initial_one_time_burst(&self) -> u64
Returns the initially configured one time burst budget.
Trait Implementations
sourceimpl Clone for TokenBucket
impl Clone for TokenBucket
sourcefn clone(&self) -> TokenBucket
fn clone(&self) -> TokenBucket
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for TokenBucket
impl Debug for TokenBucket
sourceimpl PartialEq<TokenBucket> for TokenBucket
impl PartialEq<TokenBucket> for TokenBucket
sourcefn eq(&self, other: &TokenBucket) -> bool
fn eq(&self, other: &TokenBucket) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &TokenBucket) -> bool
fn ne(&self, other: &TokenBucket) -> bool
This method tests for !=.
impl StructuralPartialEq for TokenBucket
Auto Trait Implementations
impl RefUnwindSafe for TokenBucket
impl Send for TokenBucket
impl Sync for TokenBucket
impl Unpin for TokenBucket
impl UnwindSafe for TokenBucket
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more