pub struct DirectRateLimiter { /* private fields */ }
Available on crate feature
rate-limiting
only.Expand description
A direct (non-keyed) rate limiter for simple use cases where all requests share the same limit
Implementations§
Source§impl DirectRateLimiter
impl DirectRateLimiter
Sourcepub fn direct(quota: Quota) -> DirectRateLimiter
pub fn direct(quota: Quota) -> DirectRateLimiter
Create a direct (global) rate limiter that applies to all requests
§Example
ⓘ
use http_cache::rate_limiting::{DirectRateLimiter, Quota};
use std::time::Duration;
use std::num::NonZero;
// Allow 10 requests per minute total
let quota = Quota::per_minute(NonZero::new(10).unwrap());
let limiter = DirectRateLimiter::direct(quota);
Trait Implementations§
Source§impl CacheAwareRateLimiter for DirectRateLimiter
impl CacheAwareRateLimiter for DirectRateLimiter
Source§fn until_key_ready<'life0, 'life1, 'async_trait>(
&'life0 self,
_key: &'life1 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DirectRateLimiter: 'async_trait,
fn until_key_ready<'life0, 'life1, 'async_trait>(
&'life0 self,
_key: &'life1 str,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DirectRateLimiter: 'async_trait,
Wait until a request to the given key (typically a domain or URL) is allowed
This method should block until the rate limit allows the request to proceed
Auto Trait Implementations§
impl !Freeze for DirectRateLimiter
impl RefUnwindSafe for DirectRateLimiter
impl Send for DirectRateLimiter
impl Sync for DirectRateLimiter
impl Unpin for DirectRateLimiter
impl UnwindSafe for DirectRateLimiter
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> 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