Crates.io | tokenbucket |
lib.rs | tokenbucket |
version | 0.1.6 |
source | src |
created_at | 2020-08-21 19:31:58.587556 |
updated_at | 2024-11-03 23:01:39.956225 |
description | Provies a token-bucket algorithm with a simple API. |
homepage | |
repository | https://github.com/nathan-fiscaletti/tokenbucket-rs |
max_upload_size | |
id | 279308 |
size | 13,487 |
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.