pub enum Algorithm {
TokenBucket {
capacity: u64,
refill_rate: f64,
},
SlidingWindowLog {
max_requests: u64,
window: Duration,
},
FixedWindow {
max_requests: u64,
window: Duration,
},
}Expand description
Rate limiting algorithm configuration
Variants§
TokenBucket
Token bucket algorithm
Tokens are added at a fixed rate and consumed on each request. Allows bursts up to the bucket capacity.
Fields
SlidingWindowLog
Sliding window log algorithm
Tracks individual request timestamps within a sliding window. Most accurate but requires more storage.
FixedWindow
Fixed window algorithm
Divides time into fixed windows and counts requests per window. Simple but can allow bursts at window boundaries.
Implementations§
Source§impl Algorithm
impl Algorithm
Sourcepub fn token_bucket_default() -> Self
pub fn token_bucket_default() -> Self
Create a token bucket algorithm with default values (100 capacity, 10/sec refill)
Sourcepub fn sliding_window_default() -> Self
pub fn sliding_window_default() -> Self
Create a sliding window algorithm with default values (100 requests per minute)
Sourcepub fn fixed_window_default() -> Self
pub fn fixed_window_default() -> Self
Create a fixed window algorithm with default values (100 requests per minute)
Sourcepub fn description(&self) -> String
pub fn description(&self) -> String
Get a human-readable description of the algorithm
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Algorithm
impl RefUnwindSafe for Algorithm
impl Send for Algorithm
impl Sync for Algorithm
impl Unpin for Algorithm
impl UnsafeUnpin for Algorithm
impl UnwindSafe for Algorithm
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<R, D> DepsPresent<D> for R
Source§impl<T> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Returns the TypeId of this type (for internal use)
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
Returns the type name for debugging