pub struct RateLimiter { /* private fields */ }Expand description
Bounded in-process token-bucket limiter.
This implementation is intentionally the simple single-instance default. Applications that require cross-instance enforcement should place a distributed limiter at their ingress or provide an application-owned adapter instead of assuming this process-local state is global.
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(
capacity: NonZeroU32,
refill_interval: Duration,
) -> Result<Self, RateLimiterConfigError>
pub fn new( capacity: NonZeroU32, refill_interval: Duration, ) -> Result<Self, RateLimiterConfigError>
Creates a bounded token-bucket limiter.
Sourcepub fn with_max_tracked_keys(
capacity: NonZeroU32,
refill_interval: Duration,
max_tracked_keys: NonZeroUsize,
) -> Result<Self, RateLimiterConfigError>
pub fn with_max_tracked_keys( capacity: NonZeroU32, refill_interval: Duration, max_tracked_keys: NonZeroUsize, ) -> Result<Self, RateLimiterConfigError>
Creates a limiter with an explicit bound for retained client keys.
Sourcepub fn check(&self, key: impl AsRef<str>) -> RateLimitOutcome
pub fn check(&self, key: impl AsRef<str>) -> RateLimitOutcome
Applies the limiter using its monotonic process clock.
Trait Implementations§
Source§impl Clone for RateLimiter
impl Clone for RateLimiter
Auto Trait Implementations§
impl !RefUnwindSafe for RateLimiter
impl !UnwindSafe for RateLimiter
impl Freeze for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnsafeUnpin 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