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

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.

Attempts to consume tokens from the bucket and returns whether the action succeeded.

“Manually” adds tokens to bucket.

Returns the capacity of the token bucket.

Returns the remaining one time burst budget.

Returns the time in milliseconds required to to completely fill the bucket.

Returns the current budget (one time burst allowance notwithstanding).

Returns the initially configured one time burst budget.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.