Burster ⏩
Burster is a high quality and lightweigh crate providing stack allocated rate limiters with minimal dependencies.
Guaranteed to work on no_std targets, but also comfortable on standard targets.
Supported rate limiter types
- Token bucket
- Fixed window
- Sliding window
- ..something else? Make a request or open a PR :)
Usage
On std targets usage is simple. Install the crate with default features enabled and
you'll get access to straightforward utility functions for instantiating limiters.
// Instantiate a token bucket that allowes an average consume
// rate of 100 tokens per second and with bucket_size = 10
let mut bucket = token_bucket;
// Use the bucket:
if bucket.try_consume_one.is_ok else
On no_std targets you'll have to install the crate with default features disabled and
provide bindings to your platforms clock functionality in the form of a closure that returns
the current timestamp as u64 milliseconds.
// Instantiate a token bucket that allowes an average consume
// rate of 100 tokens per second and with bucket_size = 10
let mut bucket = new_with_time_provider;
The time provider closure should return a monotonous nondecreasing timestamp, which does not have to be bound to a specific epoch. It can, for example, simply be a timestamp from the last system boot.