StorageEntry

Struct StorageEntry 

Source
pub struct StorageEntry {
    pub count: u64,
    pub window_start: u64,
    pub tat: Option<u64>,
    pub tokens: Option<f64>,
    pub last_update: u64,
    pub prev_count: Option<u64>,
    pub timestamps: Option<Vec<u64>>,
    pub metadata: Option<Vec<u8>>,
}
Expand description

Entry stored in the storage backend.

This struct contains all state needed by rate limiting algorithms, designed to be flexible enough for any algorithm type.

Fields§

§count: u64

Request count (for window-based algorithms).

§window_start: u64

Window start timestamp (Unix milliseconds).

§tat: Option<u64>

Theoretical Arrival Time for GCRA (Unix milliseconds).

§tokens: Option<f64>

Available tokens (for token bucket algorithm).

§last_update: u64

Last update timestamp (Unix milliseconds).

§prev_count: Option<u64>

Previous window count (for sliding window).

§timestamps: Option<Vec<u64>>

Request timestamps (for sliding log algorithm).

§metadata: Option<Vec<u8>>

Optional metadata (algorithm-specific).

Implementations§

Source§

impl StorageEntry

Source

pub fn new(count: u64, window_start: u64) -> Self

Create a new storage entry for window-based algorithms.

Source

pub fn with_tat(tat: u64) -> Self

Create a storage entry for GCRA algorithm.

Source

pub fn with_tokens(tokens: f64, last_update: u64) -> Self

Create a storage entry for token bucket.

Source

pub fn with_timestamps(timestamps: Vec<u64>) -> Self

Create a storage entry for sliding log.

Source

pub fn set_tat(self, tat: u64) -> Self

Set the TAT value.

Source

pub fn set_tokens(self, tokens: f64) -> Self

Set the token count.

Source

pub fn set_last_update(self, last_update: u64) -> Self

Set the last update timestamp.

Source

pub fn set_prev_count(self, count: u64) -> Self

Set previous window count.

Source

pub fn set_metadata(self, metadata: Vec<u8>) -> Self

Set metadata.

Source

pub fn tokens_or_default(&self) -> f64

Get tokens, defaulting to 0.0 if not set.

Source

pub fn tat_or_default(&self) -> u64

Get TAT, defaulting to 0 if not set.

Trait Implementations§

Source§

impl Clone for StorageEntry

Source§

fn clone(&self) -> StorageEntry

Returns a duplicate 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 StorageEntry

Source§

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

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

impl Default for StorageEntry

Source§

fn default() -> StorageEntry

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for StorageEntry

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for StorageEntry

Source§

fn eq(&self, other: &StorageEntry) -> 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 Serialize for StorageEntry

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for StorageEntry

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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,