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
//! Rate limiting algorithms.
//!
//! This module defines the core abstraction for rate limiting algorithms
//! used by the crate.
//!
//! A rate limiter represents the state and logic required to enforce
//! limits for **a single identity** (e.g. one user or one IP).
//!
//! Higher-level components (stores and middleware) are responsible for
//! managing *multiple* rate limiters and mapping them to request keys.
/// A rate limiting algorithm for a single identity.
///
/// Implementations of this trait encapsulate the logic required to decide
/// whether an action is allowed at a given point in time.
///
/// ## Important
///
/// - A `RateLimiter` instance is **not shared** across identities.
/// - Implementations are expected to be **stateful**.
/// - Concurrency control is handled by the store, not the limiter itself.
///
/// This trait is intentionally minimal so that different algorithms
/// (token bucket, sliding window, leaky bucket, etc.) can be implemented
/// interchangeably.