pub struct DistributedRateLimiter<B: RateLimitBackend> { /* private fields */ }Available on crate feature
distributed-rate-limit only.Expand description
Implementations§
Source§impl<B: RateLimitBackend> DistributedRateLimiter<B>
impl<B: RateLimitBackend> DistributedRateLimiter<B>
Sourcepub fn new(
backend: B,
namespace: impl Into<String>,
limit_per_window: u64,
window_secs: u64,
) -> Self
pub fn new( backend: B, namespace: impl Into<String>, limit_per_window: u64, window_secs: u64, ) -> Self
Sourcepub fn is_limited(&self, source: IpAddr) -> Result<bool, ServerError>
pub fn is_limited(&self, source: IpAddr) -> Result<bool, ServerError>
Returns true when the source should be throttled.
§Examples
use http_handle::distributed_rate_limit::{DistributedRateLimiter, InMemoryBackend};
use std::net::IpAddr;
let limiter = DistributedRateLimiter::new(InMemoryBackend::default(), "ip", 1, 60);
let ip: IpAddr = "127.0.0.1".parse().expect("ip");
let _ = limiter.is_limited(ip);
assert_eq!(1, 1);§Errors
Returns backend errors when increment operations fail.
§Panics
This function does not panic.
Trait Implementations§
Source§impl<B: Clone + RateLimitBackend> Clone for DistributedRateLimiter<B>
impl<B: Clone + RateLimitBackend> Clone for DistributedRateLimiter<B>
Source§fn clone(&self) -> DistributedRateLimiter<B>
fn clone(&self) -> DistributedRateLimiter<B>
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 moreAuto Trait Implementations§
impl<B> Freeze for DistributedRateLimiter<B>
impl<B> RefUnwindSafe for DistributedRateLimiter<B>where
B: RefUnwindSafe,
impl<B> Send for DistributedRateLimiter<B>
impl<B> Sync for DistributedRateLimiter<B>
impl<B> Unpin for DistributedRateLimiter<B>
impl<B> UnsafeUnpin for DistributedRateLimiter<B>
impl<B> UnwindSafe for DistributedRateLimiter<B>where
B: RefUnwindSafe,
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