Generic Cell Rate (GCR) algorithm
A fast, simple, and small Generic Cell Rate (GCR) algorithm implementation with zero dependencies
that allows for dynamic rate adjustment.
Usage
use Gcr;
let mut rate = new.unwrap;
// 10 units allowed every second with a max burst of 30 units at once
rate.request.unwrap; // Leftover capacity is now 10
rate.request.unwrap_err; // Returns `DeniedFor(1 second)`
Rate adjustment
[Gcr::adjust] can be used to change the rate of the limiter while preserving the current capacity.
It accepts the same parameters as [Gcr::new].
rate.adjust.unwrap;
// 20 units allowed every second with a max burst of 30 units at once
Capacity
[Gcr::capacity] can be used to get the current capacity of the rate limiter without making a request.
rate.capacity;