Struct ratelimit_meter::Limiter
[−]
[src]
pub struct Limiter { /* fields omitted */ }
A builder object that can be used to construct rate-limiters as meters.
Methods
impl Limiter
[src]
A builder pattern implementation that can construct deciders.
Basic example
This example constructs a decider that considers every cell compliant:
let mut limiter = Limiter::new().build::<Allower>().unwrap(); for _i in 1..3 { println!("{:?}...", limiter.check()); }
fn new() -> Limiter
[src]
Returns a default (useless) limiter without a capacity or cell weight, and a time_unit of 1 second.
fn capacity<'a>(&'a mut self, capacity: u32) -> &'a mut Limiter
[src]
Sets the capacity of the limiter's "bucket" in elements per time_unit
.
See time_unit
.
fn weight<'a>(&'a mut self, weight: u32) -> &'a mut Limiter
[src]
Sets the "weight" of each cell being checked against the bucket. Each cell fills the bucket by this much.
fn time_unit<'a>(&'a mut self, time_unit: Duration) -> &'a mut Limiter
[src]
Sets the "unit of time" within which the bucket drains.
The assumption is that in a period of time_unit
(if no cells
are being checked), the bucket is fully drained.
fn build<D>(&self) -> Result<D> where
D: Decider,
[src]
D: Decider,
Builds and returns a concrete structure that implements the Decider trait.