rate-limiters-rs
A Rust library implementing popular rate limiting algorithms.
README versions:
- English: README.md
- Русский: README_RU.md
Description
This library provides simple and efficient implementations of rate limiting algorithms for Rust applications. Useful for controlling request flow or limiting load on your services. Available implementations:
Installation
Usage
All usage examples can be found in the examples directory.
Leaky Bucket
Code example:
use thread;
use ;
use LeakyBucket;
use r#
Output:
[ 0.00s] Request #001 | Allowed | Limit: 3 | Remaining: 3 | Used: 0 | Reset: 1756307371
[ 0.30s] Request #002 | Allowed | Limit: 3 | Remaining: 2 | Used: 1 | Reset: 1756307372
[ 0.60s] Request #003 | Allowed | Limit: 3 | Remaining: 2 | Used: 1 | Reset: 1756307373
[ 0.90s] Request #004 | Rate limited | Limit: 3 | Remaining: 1 | Used: 2 | Reset: 1756307374
[ 1.20s] Request #005 | Allowed | Limit: 3 | Remaining: 1 | Used: 2 | Reset: 1756307374
[ 1.50s] Request #006 | Rate limited | Limit: 3 | Remaining: 1 | Used: 2 | Reset: 1756307375
[ 1.81s] Request #007 | Rate limited | Limit: 3 | Remaining: 1 | Used: 2 | Reset: 1756307375
[ 2.11s] Request #008 | Allowed | Limit: 3 | Remaining: 1 | Used: 2 | Reset: 1756307375
[ 2.41s] Request #009 | Rate limited | Limit: 3 | Remaining: 0 | Used: 3 | Reset: 1756307376
[ 2.71s] Request #010 | Rate limited | Limit: 3 | Remaining: 1 | Used: 2 | Reset: 1756307376
License
MIT License. See LICENSE for details.