1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Rate limiting on a caller-supplied clock: GCRA, token bucket and fixed
//! window, each a small `Copy` value behind the shared [`Gate`] contract.
//!
//! The crate is `no_std` and allocation-free; it reads no clock. `now` is a
//! [`Duration`](core::time::Duration) since an epoch the caller picks, and so
//! is every span. A refused call answers [`Refusal`] and changes nothing.
//!
//! The `std` feature adds [`KeyedGcra`], which keeps per-key GCRA state in a
//! sharded, mutex-guarded map.
//!
//! ```
//! use core::num::NonZeroU64;
//! use core::time::Duration;
//! use throttle_machines::{Gate, Gcra, GcraPolicy, Refusal};
//!
//! let policy = GcraPolicy::per(Duration::from_secs(1), NonZeroU64::new(2).unwrap(), NonZeroU64::MIN)
//! .unwrap();
//! let mut gcra = Gcra::new(policy);
//! let now = Duration::from_secs(100);
//! assert_eq!(gcra.check(now), Ok(0));
//! assert_eq!(gcra.check(now), Err(Refusal::Throttled));
//! assert_eq!(gcra.retry_after(now), Duration::from_millis(500));
//! ```
extern crate std;
/// Compiles and runs the README's examples as doctests.
;
pub use ;
pub use Gate;
pub use ;
pub use KeyedGcra;
pub use Refusal;
pub use ;