pub struct Throttle { /* private fields */ }Expand description
Rate limiting middleware
Apply rate limits to routes using named limiters or inline limits.
Implements Middleware directly for use with .middleware().
§Named limiter (from registry)
ⓘ
// Register in bootstrap
RateLimiter::define("api", |req| Limit::per_minute(60));
// Apply to routes
get!("/api/users", handler).middleware(Throttle::named("api"))§Inline limits
ⓘ
get!("/health", handler).middleware(Throttle::per_minute(120))Implementations§
Source§impl Throttle
impl Throttle
Sourcepub fn named(name: &str) -> Self
pub fn named(name: &str) -> Self
Create a throttle that resolves from the named limiter registry
The named limiter is evaluated per-request, allowing dynamic limits. If the named limiter doesn’t exist, the request is allowed (fail-open).
Sourcepub fn per_second(max: u32) -> Self
pub fn per_second(max: u32) -> Self
Create a throttle with an inline limit of N requests per second
Sourcepub fn per_minute(max: u32) -> Self
pub fn per_minute(max: u32) -> Self
Create a throttle with an inline limit of N requests per minute
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Throttle
impl !RefUnwindSafe for Throttle
impl Send for Throttle
impl Sync for Throttle
impl Unpin for Throttle
impl UnsafeUnpin for Throttle
impl !UnwindSafe for Throttle
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