pub struct RateLimiter { /* private fields */ }Expand description
Rate limiter for tracking requests and connections
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(config: RateLimitConfig) -> Self
pub fn new(config: RateLimitConfig) -> Self
Create a new rate limiter
Sourcepub async fn check_request_rate(&self, ip: IpAddr) -> Result<bool>
pub async fn check_request_rate(&self, ip: IpAddr) -> Result<bool>
Check if an IP is allowed to make a request
Sourcepub async fn can_connect(&self, ip: IpAddr) -> Result<bool>
pub async fn can_connect(&self, ip: IpAddr) -> Result<bool>
Check if an IP can establish a new connection
Sourcepub async fn remove_connection(&self, ip: IpAddr)
pub async fn remove_connection(&self, ip: IpAddr)
Remove a connection for an IP
Sourcepub async fn get_stats(&self) -> RateLimitStats
pub async fn get_stats(&self) -> RateLimitStats
Get statistics about rate limiting
Auto Trait Implementations§
impl !Freeze for RateLimiter
impl !RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl !UnwindSafe for RateLimiter
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