RateFlow
A declarative, flexible, and high-performance rate limiting library for Rust.
Features
- Declarative API - Configure complex rate limits with a simple, readable builder pattern
- Custom Strategies - Define different rate limits per endpoint, user tier, or client
- Multiple Algorithms - Token bucket and sliding window implementations
- High Performance - Optimized for low overhead in high-traffic scenarios
- Flexible Identification - Rate limit by IP address, API key, user ID, or custom identifiers
Installation
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Quick Start
use ;
// Create a rate limiter with 100 requests per minute
let limiter = builder
.limit
.window
.build
.unwrap;
// Check if a request is allowed
let client_id = "user@example.com";
if limiter.check.await else
Multi-Tier Example
use ;
// Configure different limits for different user tiers
let limiter = builder
.add_tier
.add_tier
.build
.unwrap;
// Check with tier information
if limiter.check_tier.await
License
Apache 2