Module rate
Expand description
Rate primitives: express “N units per period” and enforce it.
The core of this module is sans-IO and no_std: TokenBucket never
reads a clock, the caller provides time as monotonic nanoseconds. This
keeps it trivially testable and embeddable in other sans-IO state
machines (e.g. a send scheduler pacing datagrams).
On top (behind the std feature) RateLimiter wraps a TokenBucket
in a cheap-to-clone shared handle that can wait (pace) or reject
(rate limit) using tokio timers.
Units are whatever you want them to be: requests, connections, messages, bytes.
Structs§
- Rate
- A rate:
unitsperperperiod. - Rate
Limiter - A cheap-to-clone async handle around a shared
TokenBucket: clones share the same budget. - Token
Bucket - A sans-IO token bucket: spend units at a bounded
Ratewith a configurable burst capacity.
Enums§
- Acquire
- The result of
TokenBucket::try_acquire(andRateLimiter::try_acquire).