htb-0.1.0 has been yanked.
Hierarchical token Bucket
This crate implements Hierarchical Token Bucket algorithm with fixed structure https://en.wikipedia.org/wiki/Token_bucket#Hierarchical_token_bucket
Crate does not rely on periodic updates to maintain the token buckets which means it can be updated right before requesting tokens
use *;
use Duration;
// let's implement a rate limiter with two required properties:
// - packet rate should not exceed 250 msg per second
// - packet rate should not exceed 1500 msg per 15 seconds
let mut htb = HTB new?;
// we are allowed a single 250 token burst
assert!;
assert!;
htb.advance;
// after this point established packet rate obeys "long" indefinitely
for _ in 0..10
// if we stop consuming tokens for some time
htb.advance;
assert!;
// we get more bursts
assert!;
# Ok::