Struct diem_rate_limiter::rate_limit::Bucket[][src]

pub struct Bucket { /* fields omitted */ }
Expand description

A token bucket object that keeps track of everything related to a key This can be used as a standalone rate limiter; however, to make it more useful it should be wrapped in an Arc and a Mutex to be shared across threads.

Implementations

A fully open rate limiter, to allow for ignoring rate limiting for tests

Determine if an entire batch can be passed through This is important for message based rate limiting, where the whole message has to make it through, or else it must be rejected. A result of None means it cannot ever be allowed through, as it’s bigger than the size of the bucket.

Returns usize of tokens allowed. May be less than requested. For best effort, caller should return unused tokens with add_tokens

Tells us when the next refill is

Tells us when an entire batch will make it through. Useful for Async work to wait until all tokens are ready. Returns None if it is never possible.

Returns tokens that were unused

Trait Implementations

Formats the value using the given formatter. 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

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

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.