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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! # Volga Rate Limiter
//!
//! A lightweight and efficient rate-limiting library for Rust.
//!
//! This crate provides in-memory rate limiting algorithms designed
//! for high-performance HTTP services and middleware.
//!
//! ## Overview
//!
//! Rate limiting is used to control the number of requests that a client
//! (or a group of clients) can perform within a given time window.
//! Typical use cases include:
//!
//! - Protecting APIs from abuse or accidental overload
//! - Enforcing fair usage policies
//! - Applying different limits for anonymous users, authenticated users,
//! tenants, or API keys
//!
//! This crate focuses on **per-node, in-memory** rate limiting.
//! It is intentionally simple and fast, and does **not** attempt to
//! synchronize state across multiple processes or machines.
//!
//! ## Algorithms
//!
//! The following rate-limiting algorithms are provided:
//!
//! - [`FixedWindowRateLimiter`]
//! - Counts requests in discrete, fixed-size time windows
//! - Very fast and simple
//! - May allow short bursts at window boundaries
//!
//! - [`SlidingWindowRateLimiter`]
//! - Uses a sliding time window with linear weighting
//! - Provides smoother request distribution
//! - Slightly more expensive than a fixed window
//!
//! - [`TokenBucketRateLimiter`]
//! - Allows bursts up to a token bucket capacity
//! - Enforces a steady average refill rate
//! - Simple and flexible for bursty traffic
//!
//! - [`GcraRateLimiter`]
//! - Uses the Generic Cell Rate Algorithm (GCRA)
//! - Smooths traffic with explicit burst tolerance
//! - Accurate average rate enforcement
//!
//! ## Time Source Abstraction
//!
//! All rate limiters are built on top of a pluggable [`TimeSource`] abstraction.
//! This allows:
//!
//! - Deterministic and fast unit testing
//! - Custom time implementations if needed
//!
//! The default implementation, [`SystemTimeSource`], is based on
//! `std::time::Instant`.
//!
//! ## Concurrency Model
//!
//! The rate limiters are designed to be:
//!
//! - Thread-safe
//! - Lock-free or minimally locking on the hot path
//! - Safe to share between async tasks and threads
//!
//! Internal state is optimized for frequent reads and updates under
//! high contention.
//!
//! ## Usage
//!
//! The rate limiters are intended to be embedded into higher-level
//! frameworks or middleware layers.
pub use ;