pub trait Limiter: Send + Sync {
type Policy: RateLimitPolicy;
type Error: Error + Send + Sync + 'static;
// Required methods
fn check(
&self,
check: &Check<'_, Self::Policy>,
) -> impl Future<Output = Result<Decision, Self::Error>> + Send;
fn check_all(
&self,
checks: &[Check<'_, Self::Policy>],
) -> impl Future<Output = Result<BatchDecision, Self::Error>> + Send;
}Expand description
An asynchronous, backend-independent rate limiter.
Implementations evaluate one check or an atomic batch using their own
authoritative time source. The returned futures are Send, so adapters
can await them on a multithreaded executor without Runlimit depending on a
particular async runtime.
This trait uses return-position impl Future for static dispatch without
requiring a boxed future. It is intentionally not object-safe. Applications
that need runtime backend selection can implement Limiter for an
application-owned enum and delegate to each variant. The executor
portability guarantee also requires limiter and error types to be Send
and Sync, excluding deliberately single-thread-only implementations.
Required Associated Types§
Sourcetype Policy: RateLimitPolicy
type Policy: RateLimitPolicy
Policy algorithm supported by this backend.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".