pub struct SlidingWindowRateLimiter { /* private fields */ }Expand description
Sliding window rate limiter implementation.
Tracks individual request timestamps within a time window for precise rate limiting. More memory-intensive than token bucket but provides exact request counting.
Implementations§
Source§impl SlidingWindowRateLimiter
impl SlidingWindowRateLimiter
Sourcepub fn new(max_requests: usize, window_seconds: u64) -> SlidingWindowRateLimiter
pub fn new(max_requests: usize, window_seconds: u64) -> SlidingWindowRateLimiter
Creates a new sliding window rate limiter.
§Arguments
max_requests- Maximum requests allowed in the time windowwindow_seconds- Time window duration in seconds
Sourcepub fn is_allowed(&self) -> bool
pub fn is_allowed(&self) -> bool
Checks if a request is allowed under the rate limit.
If allowed, records the request timestamp and returns true.
Otherwise returns false.
Sourcepub fn current_requests(&self) -> usize
pub fn current_requests(&self) -> usize
Returns the current number of requests in the window.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SlidingWindowRateLimiter
impl RefUnwindSafe for SlidingWindowRateLimiter
impl Send for SlidingWindowRateLimiter
impl Sync for SlidingWindowRateLimiter
impl Unpin for SlidingWindowRateLimiter
impl UnwindSafe for SlidingWindowRateLimiter
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).