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§

Modules§

  • 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

Structs§

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

Type Aliases§