Expand description
Rate limiting algorithms for high-performance applications.
This crate provides three rate limiting algorithms:
- GCRA (Generic Cell Rate Algorithm)
- Token Bucket
- Fixed Window
All three implement the shared gate::Gate contract: a pure,
caller-holds-state decision returning a gate::Decision.
All algorithms are no_std compatible when the std feature is disabled.
With std, KeyedGcra keeps per-key GCRA state on a monotonic clock.
Re-exports§
pub use fixed_window::FixedWindow;pub use fixed_window::FixedWindowParams;pub use fixed_window::FixedWindowState;pub use gate::Decision;pub use gate::Gate;pub use gcra::Gcra;pub use gcra::GcraParams;pub use keyed::KeyedGcra;pub use token_bucket::TokenBucket;pub use token_bucket::TokenBucketParams;pub use token_bucket::TokenBucketState;
Modules§
- fixed_
window - Fixed window: count requests per window; reset when it expires. Simple, but allows bursts at window boundaries.
- gate
- The shared admission-gate contract: pure
check/peekover caller-held state, returning aDecision. Every rate limiter implementsGate. - gcra
- Generic Cell Rate Algorithm (GCRA): smooth rate limiting via a Theoretical Arrival Time (TAT) advanced by an emission interval per request.
- keyed
- Keyed GCRA: one TAT per key in a sharded map, on a monotonic clock.
- token_
bucket - Token bucket: burst capacity over a steady refill rate; each request consumes one token.