pub struct DistributedRateLimiter { /* private fields */ }Expand description
Distributed rate limiter
Uses DistributedBackend to implement cross-instance shared fixed window rate limiting.
Suitable for multi-instance deployment scenarios.
Implementations§
Source§impl DistributedRateLimiter
impl DistributedRateLimiter
Sourcepub fn new(
backend: Arc<dyn DistributedBackend>,
max_requests: u64,
window_secs: u64,
) -> DistributedRateLimiter
pub fn new( backend: Arc<dyn DistributedBackend>, max_requests: u64, window_secs: u64, ) -> DistributedRateLimiter
Creates a distributed rate limiter
backend: distributed backend (e.g.,InMemoryBackend)max_requests: maximum number of requests allowed within each windowwindow_secs: window size (seconds)
Sourcepub fn in_memory(max_requests: u64, window_secs: u64) -> DistributedRateLimiter
pub fn in_memory(max_requests: u64, window_secs: u64) -> DistributedRateLimiter
Creates a distributed rate limiter using an in-memory backend (convenience method)
Trait Implementations§
Source§impl RateLimiter for DistributedRateLimiter
impl RateLimiter for DistributedRateLimiter
fn acquire(&self, key: &str) -> Result<RateLimitResult, RateLimitError>
fn try_acquire(&self, key: &str) -> Result<RateLimitResult, RateLimitError>
fn reset(&self, key: &str) -> Result<(), RateLimitError>
Auto Trait Implementations§
impl !RefUnwindSafe for DistributedRateLimiter
impl !UnwindSafe for DistributedRateLimiter
impl Freeze for DistributedRateLimiter
impl Send for DistributedRateLimiter
impl Sync for DistributedRateLimiter
impl Unpin for DistributedRateLimiter
impl UnsafeUnpin for DistributedRateLimiter
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more