pub struct RequestRateLimiter { /* private fields */ }Expand description
An exact sliding-window limiter with bounded per-host state.
Host names are hashed with a per-instance random key and never retained. Hash collisions can only make admission stricter. Callers should pass the canonical host so aliases do not receive separate windows.
Implementations§
Source§impl RequestRateLimiter
impl RequestRateLimiter
pub fn new(config: RateLimitConfig) -> Result<Self, RateLimitConfigError>
pub fn config(&self) -> RateLimitConfig
Sourcepub fn check(&self, canonical_host: &str, now: Instant) -> RateLimitDecision
pub fn check(&self, canonical_host: &str, now: Instant) -> RateLimitDecision
Atomically admits and records one request, or reports the limiting window and the earliest useful retry time.
pub fn tracked_hosts(&self) -> usize
Trait Implementations§
Source§impl Clone for RequestRateLimiter
impl Clone for RequestRateLimiter
Auto Trait Implementations§
impl Freeze for RequestRateLimiter
impl RefUnwindSafe for RequestRateLimiter
impl Send for RequestRateLimiter
impl Sync for RequestRateLimiter
impl Unpin for RequestRateLimiter
impl UnsafeUnpin for RequestRateLimiter
impl UnwindSafe for RequestRateLimiter
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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