pub struct RateLimit(/* private fields */);Expand description
builder for client ip address based rate limiting middleware.
§Examples
App::new()
.at("/", get(handler_service(|| async { "hello,world!" })))
// rate limit to 60 rps for one ip address.
.enclosed(RateLimit::per_minute(60));Implementations§
Source§impl RateLimit
impl RateLimit
Sourcepub fn per_second(max_burst: u32) -> Self
pub fn per_second(max_burst: u32) -> Self
Construct a RateLimit for a number of cells per_second period. The given number of cells is also assumed to be the maximum burst size.
§Panics
- When max_burst is zero.
Sourcepub fn per_minute(max_burst: u32) -> Self
pub fn per_minute(max_burst: u32) -> Self
Construct a RateLimit for a number of cells per_minute period. The given number of cells is also assumed to be the maximum burst size.
§Panics
- When max_burst is zero.
Sourcepub fn per_hour(max_burst: u32) -> Self
pub fn per_hour(max_burst: u32) -> Self
Construct a RateLimit for a number of cells per_hour period. The given number of cells is also assumed to be the maximum burst size.
§Panics
- When max_burst is zero.
Sourcepub fn with_period(replenish_1_per: Duration) -> Self
pub fn with_period(replenish_1_per: Duration) -> Self
Construct a RateLimit that replenishes one cell in a given interval.
§Panics
- When the Duration is zero.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RateLimit
impl RefUnwindSafe for RateLimit
impl Send for RateLimit
impl Sync for RateLimit
impl Unpin for RateLimit
impl UnsafeUnpin for RateLimit
impl UnwindSafe for RateLimit
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<S, Arg> ServiceExt<Arg> for Swhere
S: Service<Arg>,
impl<S, Arg> ServiceExt<Arg> for Swhere
S: Service<Arg>,
Source§fn enclosed<T>(self, build: T) -> Pipeline<Self, T, BuildEnclosed>
fn enclosed<T>(self, build: T) -> Pipeline<Self, T, BuildEnclosed>
Enclose Self with given
T as Service<<Self as Service<_>>::Response>>. In other word T
would take Self’s Service::Response type as it’s generic argument of Service<_> impl.Source§fn enclosed_fn<T, Req, O>(
self,
func: T,
) -> Pipeline<Self, AsyncFn<T>, BuildEnclosed>
fn enclosed_fn<T, Req, O>( self, func: T, ) -> Pipeline<Self, AsyncFn<T>, BuildEnclosed>
Function version of Self::enclosed method.
Source§fn map<F, Res, ResMap>(self, mapper: F) -> Pipeline<Self, Map<F>, BuildEnclosed>
fn map<F, Res, ResMap>(self, mapper: F) -> Pipeline<Self, Map<F>, BuildEnclosed>
Mutate
<<Self::Response as Service<Req>>::Future as Future>::Output type with given
closure.