[−][src]Struct ratelimit_meter::algorithms::leaky_bucket::LeakyBucket
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: 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
fn construct(
capacity: NonZeroU32,
cell_weight: NonZeroU32,
per_time_unit: Duration
) -> Result<Self, InconsistentCapacity>
[src]
capacity: NonZeroU32,
cell_weight: NonZeroU32,
per_time_unit: Duration
) -> Result<Self, InconsistentCapacity>
fn test_n_and_update(
&self,
state: &Self::BucketState,
n: u32,
t0: P
) -> Result<(), NegativeMultiDecision<TooEarly<P>>>
[src]
&self,
state: &Self::BucketState,
n: u32,
t0: P
) -> Result<(), NegativeMultiDecision<TooEarly<P>>>
fn test_and_update(
&self,
state: &Self::BucketState,
at: P
) -> Result<(), Self::NegativeDecision>
[src]
&self,
state: &Self::BucketState,
at: P
) -> Result<(), Self::NegativeDecision>
impl<P: Reference> RateLimitState<LeakyBucket<P>, P> for State<P>
[src]
fn last_touched(&self, _params: &LeakyBucket<P>) -> Option<P>
[src]
impl<P: Clone + Reference> Clone for LeakyBucket<P>
[src]
fn clone(&self) -> LeakyBucket<P>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<P: Eq + Reference> Eq for LeakyBucket<P>
[src]
impl<P: PartialEq + Reference> PartialEq<LeakyBucket<P>> for LeakyBucket<P>
[src]
fn eq(&self, other: &LeakyBucket<P>) -> bool
[src]
fn ne(&self, other: &LeakyBucket<P>) -> bool
[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,
P: Unpin,
impl<P> RefUnwindSafe for LeakyBucket<P> where
P: RefUnwindSafe,
P: RefUnwindSafe,
impl<P> UnwindSafe for LeakyBucket<P> where
P: UnwindSafe,
P: UnwindSafe,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
ⓘImportant traits for &'_ mut Wfn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,