gcr 0.1.3

A fast, simple, and small Generic Cell Rate (GCR) algorithm implementation with zero dependencies
Documentation
  • Coverage
  • 66.67%
    8 out of 12 items documented1 out of 8 items with examples
  • Size
  • Source code size: 16.09 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.13 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • rob-maron/gcr
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • rob-maron

Generic Cell Rate (GCR) algorithm

crates.io docs.rs

A fast, simple, and small Generic Cell Rate (GCR) algorithm implementation with zero dependencies that allows for dynamic rate adjustment.

Usage

use gcr::Gcr;

let mut rate = Gcr::new(10, Duration::from_secs(1), Some(30)).unwrap();
    // 10 units allowed every second with a max burst of 30 units at once

rate.request(20).unwrap(); // Leftover capacity is now 10
rate.request(20).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(20, Duration::from_secs(1), Some(30)).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();