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

pub struct LeakyBucket<P: Relative = TimeSource> { /* 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<P: Relative> Algorithm<P> for LeakyBucket<P>[src]

type BucketState = State<P>

The state of a single rate limiting bucket. Read more

type NegativeDecision = TooEarly<P>

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

fn test_and_update(
    &self,
    state: &Self::BucketState,
    at: P
) -> Result<(), Self::NegativeDecision>
[src]

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<P: Relative> RateLimitState<LeakyBucket<P>, P> for State<P>[src]

impl<P: Absolute> RateLimitStateWithClock<LeakyBucket<P>, P> for State<P>[src]

impl<P: PartialEq + Relative> PartialEq<LeakyBucket<P>> for LeakyBucket<P>[src]

impl<P: Clone + Relative> Clone for LeakyBucket<P>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<P: Eq + Relative> Eq for LeakyBucket<P>[src]

impl<P: Debug + Relative> Debug for LeakyBucket<P>[src]

Auto Trait Implementations

impl<P> Send for LeakyBucket<P>

impl<P> Sync for LeakyBucket<P>

Blanket Implementations

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

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

type Owned = T

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Erased for T