pub struct RedisQuota<'a> { /* private fields */ }
Expand description
Reference to information required for tracking quotas in Redis.
Implementations§
Source§impl<'a> RedisQuota<'a>
impl<'a> RedisQuota<'a>
Sourcepub fn new(
quota: &'a Quota,
scoping: ItemScoping,
timestamp: UnixTimestamp,
) -> Option<Self>
pub fn new( quota: &'a Quota, scoping: ItemScoping, timestamp: UnixTimestamp, ) -> Option<Self>
Creates a new RedisQuota
from a Quota
, item scoping, and timestamp.
Returns None
if the quota cannot be tracked in Redis because it’s missing
required fields (ID or window). This allows forward compatibility with
future quota types.
Sourcepub fn build_owned(&self) -> OwnedRedisQuota
pub fn build_owned(&self) -> OwnedRedisQuota
Converts this RedisQuota
to an OwnedRedisQuota
leaving the original
struct in place.
Sourcepub fn limit(&self) -> i64
pub fn limit(&self) -> i64
Returns the limit value formatted for Redis.
Returns -1
for unlimited quotas or when the limit doesn’t fit into an i64
.
Otherwise, returns the limit value as an i64
.
Sourcepub fn slot(&self) -> u64
pub fn slot(&self) -> u64
Returns the current time slot of the quota based on the timestamp.
Slots are used to determine the time bucket for rate limiting.
Sourcepub fn expiry(&self) -> UnixTimestamp
pub fn expiry(&self) -> UnixTimestamp
Returns the timestamp when the current quota window will expire.
Sourcepub fn key_expiry(&self) -> u64
pub fn key_expiry(&self) -> u64
Returns when the Redis key should expire.
This is the expiry time plus a grace period.
Methods from Deref<Target = Quota>§
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Returns whether this quota is valid for tracking.
A quota is considered invalid if any of the following conditions are true:
- The quota only applies to
DataCategory::Unknown
data categories. - The quota is counted (not limit
0
) but specifies categories with different units. - The quota references an unsupported namespace.
Sourcepub fn matches(&self, scoping: ItemScoping) -> bool
pub fn matches(&self, scoping: ItemScoping) -> bool
Checks whether the quota’s constraints match the current item.
This method determines if this quota should be applied to a given item based on its scope, categories, and namespace.
Trait Implementations§
Source§impl<'a> Clone for RedisQuota<'a>
impl<'a> Clone for RedisQuota<'a>
Source§fn clone(&self) -> RedisQuota<'a>
fn clone(&self) -> RedisQuota<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<'a> Debug for RedisQuota<'a>
impl<'a> Debug for RedisQuota<'a>
Source§impl Deref for RedisQuota<'_>
impl Deref for RedisQuota<'_>
Source§impl<'a> PartialEq for RedisQuota<'a>
impl<'a> PartialEq for RedisQuota<'a>
impl<'a> Eq for RedisQuota<'a>
impl<'a> StructuralPartialEq for RedisQuota<'a>
Auto Trait Implementations§
impl<'a> Freeze for RedisQuota<'a>
impl<'a> RefUnwindSafe for RedisQuota<'a>
impl<'a> Send for RedisQuota<'a>
impl<'a> Sync for RedisQuota<'a>
impl<'a> Unpin for RedisQuota<'a>
impl<'a> UnwindSafe for RedisQuota<'a>
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§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