Expand description
An extremely simple window rate limiter.
§Usage
In your Cargo.toml
:
[dependencies]
r8limit = "0.1"
In your code:
use std::time::Duration;
// Allow 3 attempts every 5 seconds
let mut limiter = r8limit::RateLimiter::new(3, Duration::from_secs(5));
println!("{}", limiter.attempt()); // true
println!("{}", limiter.attempt()); // true
println!("{}", limiter.attempt()); // true
println!("{}", limiter.attempt()); // false