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§
sourcefn rate_limit(&self) -> RateLimit
fn rate_limit(&self) -> RateLimit
Return current throttle policy.
sourcefn check(&self, quota: u64) -> Check
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.