Struct relay_quotas::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
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)
pub fn clean_expired(&mut self)
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 evalutes is_ok
. Otherwise, it
contains rate limits that match the given scoping.
sourcepub fn check_with_quotas(
&self,
quotas: &[Quota],
scoping: ItemScoping<'_>
) -> Self
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.
sourcepub fn iter(&self) -> RateLimitsIter<'_> ⓘ
pub fn iter(&self) -> RateLimitsIter<'_> ⓘ
Returns an iterator over the rate limits.
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 more