Skip to content

nathan-fiscaletti/tokenbucket-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A TokenBucket algorithm implementation for Rust

Topics

Resources

License

Stars

Watchers

Forks

Languages