#[non_exhaustive]pub struct RateLimitConfig {
pub per_second: u64,
pub burst_size: u32,
pub use_headers: bool,
pub cleanup_interval_secs: u64,
pub max_keys: usize,
}Expand description
Configuration for the rate-limiting middleware.
Uses a token-bucket algorithm. Each unique key (typically the client IP)
gets burst_size tokens; one token is replenished every 1 / per_second
seconds. When tokens are exhausted the request receives a
429 Too Many Requests response.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.per_second: u64Token replenish rate (tokens per second).
burst_size: u32Maximum number of tokens (requests) allowed in a burst.
use_headers: boolWhether to include x-ratelimit-* headers in responses.
cleanup_interval_secs: u64How often (in seconds) to purge expired entries from the rate-limit map.
max_keys: usizeMaximum number of tracked keys. New keys are rejected when the limit
is reached. Set to 0 to disable the cap.
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 Default for RateLimitConfig
impl Default for RateLimitConfig
Source§impl<'de> Deserialize<'de> for RateLimitConfigwhere
RateLimitConfig: Default,
impl<'de> Deserialize<'de> for RateLimitConfigwhere
RateLimitConfig: Default,
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 UnsafeUnpin 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