tokenbucket

Crates.iotokenbucket
lib.rstokenbucket
version0.1.6
sourcesrc
created_at2020-08-21 19:31:58.587556
updated_at2024-11-03 23:01:39.956225
descriptionProvies a token-bucket algorithm with a simple API.
homepage
repositoryhttps://github.com/nathan-fiscaletti/tokenbucket-rs
max_upload_size
id279308
size13,487
Nathan Fiscaletti (nathan-fiscaletti)

documentation

https://docs.rs/tokenbucket/

README

tokenbucket

Documentation GitHub license Downloads

This library provides a TokenBucket Algorithm implementation for the Rust programming language.

Install

Add the following to your Cargo.toml

[dependencies]
tokenbucket = "0.1.6"

Usage

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.

Commit count: 27

cargo fmt