relay_quotas

Struct RateLimits

source
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, now: Instant)

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 evaluates is_ok. Otherwise, it contains rate limits that match the given scoping.

source

pub fn check_with_quotas<'a>( &self, quotas: impl IntoIterator<Item = &'a 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 evaluates 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.

source

pub fn is_empty(&self) -> bool

Returns true if there are any limits contained.

This is equivalent to checking whether Self::longest returns Some or Self::iter returns an iterator with at least one item.

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

source§

type IntoIter = RateLimitsIter<'a>

Which kind of iterator are we turning this into?
source§

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

source§

type IntoIter = RateLimitsIntoIter

Which kind of iterator are we turning this into?
source§

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

source§

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>,

source§

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>,

source§

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

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T