pub struct RateLimitConfig {
pub requests_per_period: u32,
pub period_secs: u64,
pub burst_size: u32,
pub enabled: bool,
}Expand description
Rate limiting configuration
Fields§
§requests_per_period: u32Maximum requests per period
period_secs: u64Period duration in seconds
burst_size: u32Burst size (max requests at once)
enabled: boolWhether rate limiting is enabled
Implementations§
Source§impl RateLimitConfig
impl RateLimitConfig
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create configuration from environment variables
Environment variables:
RATE_LIMIT_ENABLED: Enable/disable rate limiting (default: true)RATE_LIMIT_REQUESTS: Max requests per period (default: 600)RATE_LIMIT_PERIOD_SECS: Period in seconds (default: 60)RATE_LIMIT_BURST: Burst size (default: 50)
Sourcepub fn replenish_period(&self) -> Duration
pub fn replenish_period(&self) -> Duration
The interval at which governor replenishes one request cell.
Governor is configured by period per cell, not by requests per period.
Converting with requests_per_period / period_secs in integer arithmetic
silently floors the budget — the 100-per-60s default became 1 request per
second, a 40% cut, and any budget under one request per second collapsed
to the same 1/s floor. Dividing in milliseconds keeps the configured rate.
§Returns
The delay between replenished cells; never zero, so governor always has a
valid period even for an absurdly large requests_per_period.
Trait Implementations§
Source§impl Clone for RateLimitConfig
impl Clone for RateLimitConfig
Source§fn clone(&self) -> RateLimitConfig
fn clone(&self) -> RateLimitConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RateLimitConfig
impl Debug for RateLimitConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].