This library provides a TokenBucket Algorithm implementation for the Rust programming language.
Add the following to your Cargo.toml
[dependencies]
tokenbucket = "0.1.6"
use tokenbucket::{TokenBucket, TokenAcquisitionResult};
fn main() {
let mut bucket = TokenBucket::new(5.0, 100.0);
match bucket.acquire(1.0) {
Ok(rate) => println!("rate/allow: {}, true", rate),
Err(rate) => println!("rate/allow: {}, false", rate),
}
}
See the documentation for more advanced usage examples.