Crate governor

Source
Expand description

§governor - a rate-limiting library for rust.

Governor aims to be a very efficient and ergonomic way to enforce rate limits in Rust programs. It implements the Generic Cell Rate Algorithm and keeps state in a very efficient way.

For detailed information on usage, please see the user’s guide.

§Quick example

In this example, we set up a rate limiter to allow 50 elements per second, and check that a single element can pass through.

use std::num::NonZeroU32;
use nonzero_ext::*;
use governor::{Quota, RateLimiter};

let mut lim = RateLimiter::direct(Quota::per_second(nonzero!(50u32))); // Allow 50 units per second
assert_eq!(Ok(()), lim.check());

Re-exports§

pub use state::direct::RatelimitedSink;
pub use state::direct::RatelimitedStream;

Modules§

_guide
A more in-depth guide to governor
clock
Time sources for rate limiters.
middleware
Additional, customizable behavior for rate limiters.
nanos
A time-keeping abstraction (nanoseconds) that works for storing in an atomic integer.
prelude
The collection of asynchronous traits exported from this crate.
state
State stores for rate limiters

Structs§

InsufficientCapacity
Error indicating that the number of cells tested (the first argument) is larger than the bucket’s capacity.
Jitter
An interval specification for deviating from the nominal wait time.
NotUntil
A negative rate-limiting outcome.
Quota
A rate-limiting quota.
RateLimiter
A rate limiter.

Type Aliases§

DefaultDirectRateLimiter
A rate limiter representing a single item of state in memory, running on the default clock.
DefaultKeyedRateLimiter
A rate limiter with one state per key, running on the default clock.