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: u64Request count (for window-based algorithms).
window_start: u64Window 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: u64Last 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
impl StorageEntry
Sourcepub fn new(count: u64, window_start: u64) -> Self
pub fn new(count: u64, window_start: u64) -> Self
Create a new storage entry for window-based algorithms.
Sourcepub fn with_tokens(tokens: f64, last_update: u64) -> Self
pub fn with_tokens(tokens: f64, last_update: u64) -> Self
Create a storage entry for token bucket.
Sourcepub fn with_timestamps(timestamps: Vec<u64>) -> Self
pub fn with_timestamps(timestamps: Vec<u64>) -> Self
Create a storage entry for sliding log.
Sourcepub fn set_tokens(self, tokens: f64) -> Self
pub fn set_tokens(self, tokens: f64) -> Self
Set the token count.
Sourcepub fn set_last_update(self, last_update: u64) -> Self
pub fn set_last_update(self, last_update: u64) -> Self
Set the last update timestamp.
Sourcepub fn set_prev_count(self, count: u64) -> Self
pub fn set_prev_count(self, count: u64) -> Self
Set previous window count.
Sourcepub fn set_metadata(self, metadata: Vec<u8>) -> Self
pub fn set_metadata(self, metadata: Vec<u8>) -> Self
Set metadata.
Sourcepub fn tokens_or_default(&self) -> f64
pub fn tokens_or_default(&self) -> f64
Get tokens, defaulting to 0.0 if not set.
Sourcepub fn tat_or_default(&self) -> u64
pub fn tat_or_default(&self) -> u64
Get TAT, defaulting to 0 if not set.
Trait Implementations§
Source§impl Clone for StorageEntry
impl Clone for StorageEntry
Source§fn clone(&self) -> StorageEntry
fn clone(&self) -> StorageEntry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more