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
51
52
53
54
55
//! Rate limiting for the rok ecosystem.
//!
//! # Programmatic API
//!
//! ```rust,ignore
//! use rok_rate_limit::{Limiter, LimitResult};
//!
//! let limiter = Limiter::memory();
//!
//! let result = limiter
//! .for_key("user:alice")
//! .requests(100)
//! .per(std::time::Duration::from_secs(60))
//! .check();
//!
//! match result {
//! LimitResult::Allowed { remaining, reset_epoch } => { /* proceed */ }
//! LimitResult::Exceeded { retry_after_secs } => { /* return 429 */ }
//! }
//! ```
//!
//! # Tower Middleware
//!
//! ```rust,ignore
//! use rok_rate_limit::ThrottleLayer;
//!
//! let app = Router::new()
//! .route("/api/posts", get(list_posts))
//! .layer(ThrottleLayer::by_ip("api", 100, 60)); // 100 req/min per IP
//! ```
pub use ;
pub use ;
pub use ;
use OnceLock;
static GLOBAL_LIMITER: = new;
/// Return the process-global [`Limiter`] instance (memory-backed).
///
/// Used by the `#[throttle]` proc-macro and `ThrottleLayer::global()` /
/// `ThrottleLayer::by_ip()` factory methods.