token-bucket 11.2.0

Zero-dependency, lock-free atomic GCRA, Fixed-Window, Token-Bucket, and 64-way sharded bounded keyed rate-limiting engine.
Documentation
  • Coverage
  • 100%
    28 out of 28 items documented0 out of 0 items with examples
  • Size
  • Source code size: 182.6 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.3 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates-dev/ctares
    2 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • vshengbro

token-bucket

Zero-Dependency Lock-Free Atomic GCRA, Fixed-Window, Token-Bucket & Keyed Rate Limiters

Crates.io Version Docs.rs CI Status Rust 2024 License: MIT

Workspace Overview · API Docs


Overview

token-bucket provides zero-dependency, lock-free atomic GcraLimiter, FixedWindowLimiter, TokenBucketLimiter, and a sharded, bounded KeyedRateLimiter for per-IP, per-tenant, and per-route admission control.

Installation

cargo add token-bucket

Usage

use token_bucket::{GcraConfig, KeyedRateLimiter, RateLimitPolicy};

let policy = RateLimitPolicy::Gcra(GcraConfig::from_emission_interval_ns(1_000_000, 10).unwrap());
let limiter: KeyedRateLimiter<String> = KeyedRateLimiter::new(policy, 4096).unwrap();
let decision = limiter.check_at_ns("10.0.0.1", 1_000);
assert!(decision.is_allowed());

Verification

cargo run -p crate-cli -- fmt --check
cargo clippy -p token-bucket --all-features --all-targets -- -D warnings
cargo test -p token-bucket --all-features

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For inquiries, please contact the author at root@devhub.vip.