quota
A high-performance in-memory rate limiter for Rust.
It uses a mix of Leaky Token Bucket & GCRA.
The main QuotaPool is concurrent by default. It uses DashMap for key routing and a small per-key mutex for exact quota state, so it can be shared as Arc<QuotaPool<_>> without an outer lock.
We provide 3 essential primitives: Quota, QuotaPolicy, and QuotaPool that combines both of them.
QuotaPool defaults to QuotaKey, an owned heap String.
If your quota identity is already a compact ID, interned symbol, or another key shape,
use QuotaPool<K> and construct it with QuotaPool::<K>::with_key_type(...).
Use QuotaPool::with_capacity(...) and pool.insert_keys(...) when the key set is known ahead of traffic; that keeps the hot request path on borrowed-key lookup instead of insertion.
Example use of the simple Quota (A simple 8-byte number in memory):
use Quota;
Example use of applying QuotaPolicy with a maximum capacity and RefillRate:
use ;
And now the main QuotaPool:
use ;
use Arc;
use Duration;