[][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, RateLimiter};

let mut lim = RateLimiter::direct(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.

state

State stores for rate limiters

Structs

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.

RatelimitedSink

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

RatelimitedStream

A Stream combinator which will limit the rate of items being received.

Enums

NegativeMultiDecision

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