A genuinely better token bucket for Rust: lock-free, allocation-free acquire path, cache-aligned, overflow-safe, with a one-line Tier-1 API and a mockable clock for deterministic tests.
//! The Tier-1 common case: a per-second rate limiter.
//!//! Run with `cargo run --example per_second`.
usebetter_bucket::Bucket;fnmain(){// Allow 5 requests per second, with a burst ceiling of 5.
let limiter =Bucket::per_second(5);// Fire eight requests in a tight loop. The first five drain the bucket;
// the rest are denied, because almost no time has passed to refill it.
for request in1..=8{if limiter.try_acquire(1){println!("request {request}: allowed");}else{println!("request {request}: denied (rate limited)");}}}