Function ratelimit_meter::new

source ·
pub fn new<T>(capacity: NonZeroU32, per_time_unit: Duration) -> Twhere
    T: Sized + NewImpl,
Expand description

Construct a new Decider that allows capacity cells per time unit through.

Examples

You can construct a GCRA decider like so:

use ratelimit_meter::GCRA;
let _gcra = ratelimit_meter::new::<GCRA>(NonZeroU32::new(100).unwrap(),
                                         Duration::from_secs(5));

and similarly, for a leaky bucket:

use ratelimit_meter::LeakyBucket;
let _lb = ratelimit_meter::new::<LeakyBucket>(NonZeroU32::new(100).unwrap(),
                                              Duration::from_secs(5));