Rate limiter - Rust
Lock-free GCRA rate limiter using a single-atomic CAS-loop. One tryAcquire is one load and one CAS, even at 8-way contention.
Part of the submillisecond.com cookbook. Zero external dependencies; std only.
Install
[]
= "0.4"
Quickstart
Public API
pub struct RateLimiterpub fn new(rate_per_sec: f64, burst_capacity: u64) -> Selfpub fn try_acquire(&self) -> boolpub fn rate_per_sec(&self) -> f64pub fn burst_capacity(&self) -> u64
Files
src/lib.rs- implementation.tests/- integration tests; correctness, edge cases, property/stress.examples/demo.rs- stdout walkthrough.examples/perf_main.rs- bench entry (behind theharnessfeature).
License
Dual-licensed under MIT OR Apache-2.0.