A powerful, lock-free rate limiter for Rust: multiple algorithms behind one trait, sharded per-key state, bounded-memory eviction, retry-after, and a one-line Tier-1 API. Built against hostile traffic.
//! Awaiting until a key is allowed, instead of shedding the request.
//!//! Requires the `async` feature:
//!//! ```text
//! cargo run --example async_wait --features async
//! ```
userate_net::{AsyncLimiter, RateLimiter};#[tokio::main(flavor ="current_thread")]
async fnmain(){// Five per second → a token refills roughly every 200ms.
let limiter =AsyncLimiter::new(RateLimiter::per_second(5));// Spend the whole allowance up front.
for_in0..5{let_= limiter.check("job-queue");}println!("allowance spent; awaiting a refill...");let start =std::time::Instant::now();
limiter.until_ready("job-queue").await;println!("admitted after {:?}", start.elapsed());}