pub trait Ratelimiter: Debug + Send + Sync {
    fn bucket(&self, path: &Path) -> GetBucketFuture;
    fn globally_locked(&self) -> IsGloballyLockedFuture;
    fn has(&self, path: &Path) -> HasBucketFuture;
    fn ticket(&self, path: Path) -> GetTicketFuture;

    fn wait_for_ticket(&self, path: Path) -> WaitForTicketFuture { ... }
}
Expand description

An implementation of a ratelimiter for the Discord REST API.

A default implementation can be found in InMemoryRatelimiter.

All operations are asynchronous to allow for custom implementations to use different storage backends, for example databases.

Ratelimiters should keep track of two kids of ratelimits:

  • The global ratelimit status
  • Path-specific ratelimits

To do this, clients utilizing a ratelimiter will send back response ratelimit headers via a TicketSender.

The ratelimiter itself will hand a TicketReceiver to the caller when a ticket is being requested.

Required Methods

Retrieve the basic information of the bucket for a given path.

Whether the ratelimiter is currently globally locked.

Determine if the ratelimiter has a bucket for the given path.

Retrieve a ticket to know when to send a request. The provided future will be ready when a ticket in the bucket is available. Tickets are ready in order of retrieval.

Provided Methods

Retrieve a ticket to send a request. Other than Self::ticket, this method will return a TicketSender.

This is identical to calling Self::ticket and then awaiting the TicketReceiver.

Implementors