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
<div align="center">

<img src="https://devhub.vip/pages/docs/img/logo.png" alt="token-bucket logo" height="120">

# token-bucket

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

[![Crates.io Version](https://flat.badgen.net/crates/v/token-bucket)](https://crates.io/crates/token-bucket)
[![Docs.rs](https://img.shields.io/docsrs/token-bucket?style=flat-square)](https://docs.rs/token-bucket)
[![CI Status](https://img.shields.io/github/actions/workflow/status/crates-dev/ctares/rust.yml?branch=master&style=flat-square&label=CI)](https://github.com/crates-dev/ctares/actions/workflows/rust.yml)
[![Rust 2024](https://img.shields.io/badge/edition-2024-orange.svg?style=flat-square)](https://www.rust-lang.org)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](../LICENSE)

[Workspace Overview](../README.md) ยท [API Docs](https://docs.rs/token-bucket/latest/)

</div>

---

## 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

```sh
cargo add token-bucket
```

## Usage

```rust
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

```sh
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](../LICENSE) file for details.

## Contact

For inquiries, please contact the author at [root@devhub.vip](mailto:root@devhub.vip).