An open API service indexing awesome lists of open source software.

https://github.com/nathan-fiscaletti/tokenbucket-rs

A TokenBucket algorithm implementation for Rust
https://github.com/nathan-fiscaletti/tokenbucket-rs

bucket rust token tokenbucket

Last synced: 3 months ago
JSON representation

A TokenBucket algorithm implementation for Rust

Awesome Lists containing this project

README

        

# tokenbucket

[![Documentation](https://img.shields.io/badge/docs.rs-reference-blue)](https://docs.rs/tokenbucket/)
[![GitHub license](https://img.shields.io/github/license/nathan-fiscaletti/tokenbucket-rs)](https://github.com/nathan-fiscaletti/tokenbucket-rs/blob/master/LICENSE)
[![Downloads](https://img.shields.io/crates/d/tokenbucket.svg)](https://crates.io/crates/tokenbucket)

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

## Install

Add the following to your Cargo.toml

```toml
[dependencies]
tokenbucket = "0.1.6"
```

## Usage

```rust
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](https://docs.rs/tokenbucket/) for more advanced usage examples.