[][src]Struct ratelimit_meter::algorithms::leaky_bucket::LeakyBucket

pub struct LeakyBucket { /* fields omitted */ }

Implements the industry-standard leaky bucket rate-limiting as-a-meter. The bucket keeps a "fill height", pretending to drip steadily (which reduces the fill height), and increases the fill height with every cell that is found conforming. If cells would make the bucket overflow, they count as non-conforming.

Drip implementation

Instead of having a background task update the bucket's fill level, this implementation re-computes the fill level of the bucket on every call to check and related methods.

Wait time calculation

If the cell does not fit, this implementation computes the minimum wait time until the cell can be accommodated. This minimum wait time does not account for thundering herd effects or other problems in concurrent resource acquisition, so users of this library must take care to apply positive jitter to these wait times.

Example

let mut lb = DirectRateLimiter::<LeakyBucket>::per_second(nonzero!(2u32));
assert_eq!(Ok(()), lb.check());

Trait Implementations

impl Algorithm for LeakyBucket
[src]

The state of a single rate limiting bucket. Read more

The type returned when a rate limiting decision for a single cell is negative. Each rate limiting algorithm can decide to return the type that suits it best, but most algorithms' decisions also implement NonConformance, to ease handling of how long to wait. Read more

Constructs a rate limiter with the given parameters: capacity is the number of cells to allow, weighing cell_weight, every per_time_unit. Read more

Tests if n cells can be accommodated in the rate limiter at the instant at and updates the rate-limiter state to account for the weight of the cells and updates the ratelimiter state. Read more

Tests if a single cell can be accommodated in the rate limiter at the instant at and updates the rate-limiter state to account for the weight of the cell. Read more

impl RateLimitState<LeakyBucket> for State
[src]

Returns the last time instant that the state had any relevance (i.e. the rate limiter would behave exactly as if it was a new rate limiter after this time). Read more

impl Clone for LeakyBucket
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq<LeakyBucket> for LeakyBucket
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for LeakyBucket
[src]

impl Debug for LeakyBucket
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for LeakyBucket

impl Sync for LeakyBucket

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> Erased for T