pub struct RateLimiter { /* private fields */ }Expand description
Rate limiting middleware
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(max_requests: usize, window: Duration) -> Self
pub fn new(max_requests: usize, window: Duration) -> Self
Create a new rate limiter
§Arguments
max_requests- Maximum number of requests allowed in the windowwindow- Time window for rate limiting
Sourcepub async fn check_rate_limit(&self) -> bool
pub async fn check_rate_limit(&self) -> bool
Check if a request is allowed
Sourcepub async fn record_request(&self)
pub async fn record_request(&self)
Record a request
Trait Implementations§
Source§impl Clone for RateLimiter
impl Clone for RateLimiter
Source§fn clone(&self) -> RateLimiter
fn clone(&self) -> RateLimiter
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 moreSource§impl Debug for RateLimiter
impl Debug for RateLimiter
Source§impl Middleware for RateLimiter
impl Middleware for RateLimiter
Source§fn process_request(
&self,
_req: &mut Request<Full<Bytes>>,
_ctx: &MiddlewareContext,
) -> Result<()>
fn process_request( &self, _req: &mut Request<Full<Bytes>>, _ctx: &MiddlewareContext, ) -> Result<()>
Process the request before sending
Source§fn process_response(
&self,
_resp: &mut Response<Full<Bytes>>,
_ctx: &MiddlewareContext,
) -> Result<()>
fn process_response( &self, _resp: &mut Response<Full<Bytes>>, _ctx: &MiddlewareContext, ) -> Result<()>
Process the response after receiving
Source§fn process_error(
&self,
_error: &mut SpectreError,
_ctx: &MiddlewareContext,
) -> Result<()>
fn process_error( &self, _error: &mut SpectreError, _ctx: &MiddlewareContext, ) -> Result<()>
Handle errors during request processing
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