pub struct Limit {
pub max_requests: u32,
pub window_seconds: u64,
/* private fields */
}Expand description
Declarative rate limit configuration
Defines how many requests are allowed in a time window, with optional per-key segmentation and custom 429 responses.
§Example
ⓘ
use ferro::middleware::Limit;
// 60 requests per minute, keyed by client IP (default)
let limit = Limit::per_minute(60);
// 120 requests per minute, keyed by user ID
let limit = Limit::per_minute(120).by(format!("user:{}", user_id));
// Custom 429 response
let limit = Limit::per_hour(1000).response(|| {
HttpResponse::json(serde_json::json!({"error": "Quota exceeded"})).status(429)
});Fields§
§max_requests: u32Maximum requests allowed in the window
window_seconds: u64Window duration in seconds
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Limit
impl !RefUnwindSafe for Limit
impl Send for Limit
impl Sync for Limit
impl Unpin for Limit
impl UnsafeUnpin for Limit
impl !UnwindSafe for Limit
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> 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