Struct ratelimit::Builder

source ·
pub struct Builder { /* private fields */ }
Expand description

A builder for a rate limiter.

Implementations

Creates a new Builder with the default config

Examples
let mut b = Builder::new();

Returns a Limiter from the Builder.

Example

let mut r = Builder::new().build();

Sets the number of tokens to add per interval.

Examples

let mut r = Limiter::configure()
    .quantum(100)
    .build();

Sets the number of tokens that the bucket can hold.

Examples

let mut r = Limiter::configure()
    .capacity(100)
    .build();

Set the duration between token adds.

Examples

let mut r = Limiter::configure()
    .interval(Duration::new(2, 0))
    .build();

Alternative to interval; sets the number of times that tokens will be added to the bucket each second.

Examples

let mut rate = 100_000; // 100kHz
let mut r = Limiter::configure()
    .frequency(rate)
    .build();

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.