| Crates.io | flux-limiter |
| lib.rs | flux-limiter |
| version | 0.7.2 |
| created_at | 2025-11-16 05:09:10.077638+00 |
| updated_at | 2025-12-21 05:21:44.606288+00 |
| description | A rate limiter based on the Generic Cell Rate Algorithm (GCRA). |
| homepage | https://crustyrustacean.github.io/flux-limiter/ |
| repository | https://github.com/crustyrustacean/flux-limiter |
| max_upload_size | |
| id | 1935236 |
| size | 224,830 |
A high-performance rate limiter based on the Generic Cell Rate Algorithm (GCRA) with nanosecond precision and lock-free concurrent access.
String, IpAddr, u64, etc.)Add this to your Cargo.toml:
[dependencies]
flux-limiter = "0.7.2"
use flux_limiter::{FluxLimiter, FluxLimiterConfig, SystemClock};
// Create a rate limiter: 10 requests per second with burst of 5
let config = FluxLimiterConfig::new(10.0, 5.0);
let limiter = FluxLimiter::with_config(config, SystemClock).unwrap();
// Check if a request should be allowed
match limiter.check_request("user_123") {
Ok(decision) => {
if decision.allowed {
println!("Request allowed");
} else {
println!("Rate limited - retry after {:.2}s",
decision.retry_after_seconds.unwrap_or(0.0));
}
}
Err(e) => {
eprintln!("Rate limiter error: {}", e);
// Handle error appropriately (e.g., fail-open, fail-closed)
}
}
For comprehensive documentation, including:
Please see the full documentation.
This project is licensed under the MIT License - see the License.txt file for details.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.