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
impl RateLimits
sourcepub fn add(&mut self, limit: RateLimit)
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.
sourcepub fn merge(&mut self, limits: Self)
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.
sourcepub fn is_limited(&self) -> bool
pub fn is_limited(&self) -> bool
Returns true
if this instance contains active rate limits.
sourcepub fn clean_expired(&mut self, now: Instant)
pub fn clean_expired(&mut self, now: Instant)
Removes expired rate limits from this instance.
sourcepub fn check(&self, scoping: ItemScoping<'_>) -> Self
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.
sourcepub fn check_with_quotas<'a>(
&self,
quotas: impl IntoIterator<Item = &'a Quota>,
scoping: ItemScoping<'_>,
) -> Self
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.
sourcepub fn iter(&self) -> RateLimitsIter<'_> ⓘ
pub fn iter(&self) -> RateLimitsIter<'_> ⓘ
Returns an iterator over the rate limits.
sourcepub fn longest(&self) -> Option<&RateLimit>
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.
sourcepub fn is_empty(&self) -> bool
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
impl Clone for RateLimits
source§fn clone(&self) -> RateLimits
fn clone(&self) -> RateLimits
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RateLimits
impl Debug for RateLimits
source§impl Default for RateLimits
impl Default for RateLimits
source§fn default() -> RateLimits
fn default() -> RateLimits
source§impl<'a> IntoIterator for &'a RateLimits
impl<'a> IntoIterator for &'a RateLimits
Auto Trait Implementations§
impl Freeze for RateLimits
impl RefUnwindSafe for RateLimits
impl Send for RateLimits
impl Sync for RateLimits
impl Unpin for RateLimits
impl UnwindSafe for RateLimits
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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