pub struct RateLimits { /* private fields */ }
Expand description

A collection of scoped rate limits.

This collection may be empty, indicated by is_ok. If this instance carries rate limits, they can be iterated over using iter. Additionally, rate limits can be checked for items by invoking check with the respective ItemScoping.

Implementations§

source§

impl RateLimits

source

pub fn new() -> Self

Creates an empty RateLimits instance.

source

pub fn add(&mut self, limit: RateLimit)

Adds a limit to this collection.

If a rate limit with an overlapping scope already exists, the retry_after count is merged with the existing limit. Otherwise, the new rate limit is added.

source

pub fn merge(&mut self, limits: Self)

Merges all limits into this instance.

This keeps all existing rate limits, adding new ones, and updating ones with a longer retry_after count. The resulting RateLimits contains the merged maximum.

source

pub fn is_ok(&self) -> bool

Returns true if this instance contains no active limits.

source

pub fn is_limited(&self) -> bool

Returns true if this instance contains active rate limits.

source

pub fn clean_expired(&mut self)

Removes expired rate limits from this instance.

source

pub fn check(&self, scoping: ItemScoping<'_>) -> Self

Checks whether any rate limits apply to the given scoping.

If no limits match, then the returned RateLimits instance evalutes is_ok. Otherwise, it contains rate limits that match the given scoping.

source

pub fn check_with_quotas( &self, quotas: &[Quota], scoping: ItemScoping<'_> ) -> Self

Checks whether any rate limits apply to the given scoping.

This is similar to check. Additionally, it checks for quotas with a static limit 0, and rejects items even if there is no active rate limit in this instance.

If no limits or quotas match, then the returned RateLimits instance evalutes is_ok. Otherwise, it contains rate limits that match the given scoping.

source

pub fn iter(&self) -> RateLimitsIter<'_>

Returns an iterator over the rate limits.

source

pub fn longest(&self) -> Option<&RateLimit>

Returns the longest rate limit.

If multiple rate limits have the same retry after count, any of the limits is returned.

Trait Implementations§

source§

impl Clone for RateLimits

source§

fn clone(&self) -> RateLimits

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for RateLimits

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for RateLimits

source§

fn default() -> RateLimits

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

impl<'a> IntoIterator for &'a RateLimits

§

type IntoIter = RateLimitsIter<'a>

Which kind of iterator are we turning this into?
§

type Item = &'a RateLimit

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for RateLimits

§

type IntoIter = RateLimitsIntoIter

Which kind of iterator are we turning this into?
§

type Item = RateLimit

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more