pub trait Ratelimiter:
Debug
+ Send
+ Sync {
// Required methods
fn bucket(&self, path: &Path) -> GetBucketFuture;
fn is_globally_locked(&self) -> IsGloballyLockedFuture;
fn has(&self, path: &Path) -> HasBucketFuture;
fn ticket(&self, path: Path) -> GetTicketFuture;
// Provided method
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§
Sourcefn bucket(&self, path: &Path) -> GetBucketFuture
fn bucket(&self, path: &Path) -> GetBucketFuture
Retrieve the basic information of the bucket for a given path.
Sourcefn is_globally_locked(&self) -> IsGloballyLockedFuture
fn is_globally_locked(&self) -> IsGloballyLockedFuture
Whether the ratelimiter is currently globally locked.
Sourcefn has(&self, path: &Path) -> HasBucketFuture
fn has(&self, path: &Path) -> HasBucketFuture
Determine if the ratelimiter has a bucket for the given path.
Sourcefn ticket(&self, path: Path) -> GetTicketFuture
fn ticket(&self, path: Path) -> GetTicketFuture
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§
Sourcefn wait_for_ticket(&self, path: Path) -> WaitForTicketFuture
fn wait_for_ticket(&self, path: Path) -> WaitForTicketFuture
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.