Skip to main content

RateLimiterTrait

Trait RateLimiterTrait 

Source
pub trait RateLimiterTrait:
    Send
    + Sync
    + 'static {
    // Required methods
    fn rate_limit(&self) -> RateLimit;
    fn check(&self, quota: u64) -> Check;
}
Expand description

Shared behavior for rate limiters.

Required Methods§

Source

fn rate_limit(&self) -> RateLimit

Return current throttle policy.

Source

fn check(&self, quota: u64) -> Check

Check if the request with the given quota is supposed to be allowed at the moment.

On success, the quota will be consumed. Check::Ok is returned. The caller is supposed to proceed the request with the given quota.

On failure, Check::Retry or Check::RetryAfter is returned. The caller is supposed to retry the check after the given duration or retry after receiving the signal.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§