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

pub struct LeakyBucket<P: Reference = <DefaultClock as Clock>::Instant> { /* 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.


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

Trait Implementations

impl<P: Reference> 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

impl<P: Reference> RateLimitState<LeakyBucket<P>, P> for State<P>[src]

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

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

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

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

Auto Trait Implementations

impl<P> Send for LeakyBucket<P>

impl<P> Sync for LeakyBucket<P>

impl<P> Unpin for LeakyBucket<P> where
    P: Unpin

impl<P> RefUnwindSafe for LeakyBucket<P> where
    P: RefUnwindSafe

impl<P> UnwindSafe for LeakyBucket<P> where
    P: UnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

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