async_rate_limit::limiters

Trait VariableCostRateLimiter

Source
pub trait VariableCostRateLimiter {
    // Required method
    fn wait_with_cost(&mut self, cost: usize) -> impl Future<Output = ()> + Send;
}
Expand description

A cost-based rate limiter, where each call can be of a variable cost.

Calls that cost more than all potentially available permits WILL deadlock permanently.

See TokenBucketRateLimiter for a common use case.

Required Methods§

Source

fn wait_with_cost(&mut self, cost: usize) -> impl Future<Output = ()> + Send

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl VariableCostRateLimiter for TokenBucketRateLimiter

Source§

impl<L: ThreadsafeVariableRateLimiter> VariableCostRateLimiter for L

All VariableCostRateLimiters are ThreadsafeVariableRateLimiters, since they can pass &mut self as &self.

This blanket implementation saves implementers from having to define the trait manually.