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());


A more in-depth guide to governor

Time sources for rate limiters.

Additional, customizable behavior for rate limiters.

A time-keeping abstraction (nanoseconds) that works for storing in an atomic integer.

The collection of asynchronous traits exported from this crate.

State stores for rate limiters


An interval specification for deviating from the nominal wait time.

A negative rate-limiting outcome.

A rate-limiting quota.

A rate limiter.

A [Sink][futures::Sink] combinator that only allows sending elements when the rate-limiter allows it.

A [Stream][futures::Stream] combinator which will limit the rate of items being received.


Gives additional information about the negative outcome of a batch cell decision.