[][src]Crate governor

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 5 elements per second, and check that a single element can pass through.

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

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

Modules

_guide

A more in-depth guide to governor

clock

Time sources for rate limiters.

prelude

The collection of asynchronous traits exported from this crate.

Structs

DirectRateLimiter

An in-memory rate limiter that makes direct (un-keyed) rate-limiting decisions. Direct rate limiters can be used to e.g. regulate the transmission of packets on a single connection, or to ensure that an API client stays within a service's rate limit.

Jitter

An interval specification for deviating from the nominal wait time.

NotUntil

A negative rate-limiting outcome.

Quota

A rate-limiting quota.

RatelimitedSink

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

RatelimitedStream

A stream combinator which will limit the rate of items passing through.

Enums

NegativeMultiDecision

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