tokenbucket

Crates.iotokenbucket
lib.rstokenbucket
version0.1.4
sourcesrc
created_at2020-08-21 19:31:58.587556
updated_at2024-04-09 17:39:53.221129
descriptionProvies a token-bucket algorithm with a simple API.
homepagehttps://github.com/nathan-fiscaletti/tokenbucket-rs
repository
max_upload_size
id279308
size10,281
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.4"

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: 0

cargo fmt