Struct RedisQuota

Source
pub struct RedisQuota<'a> { /* private fields */ }
Expand description

Reference to information required for tracking quotas in Redis.

Implementations§

Source§

impl<'a> RedisQuota<'a>

Source

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.

Source

pub fn build_owned(&self) -> OwnedRedisQuota

Converts this RedisQuota to an OwnedRedisQuota leaving the original struct in place.

Source

pub fn window(&self) -> u64

Returns the window size of the quota in seconds.

Source

pub fn prefix(&self) -> &'a str

Returns the prefix of the quota used for Redis key generation.

Source

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.

Source

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.

Source

pub fn expiry(&self) -> UnixTimestamp

Returns the timestamp when the current quota window will expire.

Source

pub fn key_expiry(&self) -> u64

Returns when the Redis key should expire.

This is the expiry time plus a grace period.

Source

pub fn key(&self) -> String

Returns the Redis key for this quota.

The key includes the quota ID, organization ID, and other scoping information based on the quota’s scope type. Keys are structured to ensure proper isolation between different organizations and scopes.

Methods from Deref<Target = Quota>§

Source

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.
Source

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>

Source§

fn clone(&self) -> RedisQuota<'a>

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<'a> Debug for RedisQuota<'a>

Source§

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

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

impl Deref for RedisQuota<'_>

Source§

type Target = Quota

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a> PartialEq for RedisQuota<'a>

Source§

fn eq(&self, other: &RedisQuota<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for RedisQuota<'a>

Source§

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> 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 u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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