pub struct RateLimitConfig {
pub capacity: u64,
pub refill_rate: u64,
pub refill_interval: Duration,
pub algorithm: RateLimitAlgorithm,
pub block_on_limit: bool,
}Expand description
Rate limiter configuration
Fields§
§capacity: u64Maximum tokens/requests (capacity)
refill_rate: u64Refill rate (tokens per interval)
refill_interval: DurationRefill interval
algorithm: RateLimitAlgorithmAlgorithm to use
block_on_limit: boolWhether to block or return error when limit exceeded
Implementations§
Source§impl RateLimitConfig
impl RateLimitConfig
Sourcepub fn new(capacity: u64, refill_interval: Duration) -> Self
pub fn new(capacity: u64, refill_interval: Duration) -> Self
Create a new rate limit configuration
§Arguments
capacity- Maximum tokens (burst size)refill_interval- How often to refill tokens
Sourcepub fn per_second(requests: u64) -> Self
pub fn per_second(requests: u64) -> Self
Create configuration for requests per second
Sourcepub fn per_minute(requests: u64) -> Self
pub fn per_minute(requests: u64) -> Self
Create configuration for requests per minute
Sourcepub fn with_refill_rate(self, rate: u64) -> Self
pub fn with_refill_rate(self, rate: u64) -> Self
Set the refill rate
Sourcepub fn with_algorithm(self, algorithm: RateLimitAlgorithm) -> Self
pub fn with_algorithm(self, algorithm: RateLimitAlgorithm) -> Self
Set the algorithm
Sourcepub fn with_blocking(self, block: bool) -> Self
pub fn with_blocking(self, block: bool) -> Self
Set whether to block when limit is exceeded
Trait Implementations§
Source§impl Clone for RateLimitConfig
impl Clone for RateLimitConfig
Source§fn clone(&self) -> RateLimitConfig
fn clone(&self) -> RateLimitConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RateLimitConfig
impl Debug for RateLimitConfig
Source§impl<'de> Deserialize<'de> for RateLimitConfig
impl<'de> Deserialize<'de> for RateLimitConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for RateLimitConfig
impl RefUnwindSafe for RateLimitConfig
impl Send for RateLimitConfig
impl Sync for RateLimitConfig
impl Unpin for RateLimitConfig
impl UnwindSafe for RateLimitConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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 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>
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