pub struct DistributedRateLimiter { /* private fields */ }Expand description
分布式限流器
使用 DistributedBackend 实现跨实例共享的固定窗口限流。
适用于多实例部署场景。
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
创建分布式限流器
backend:分布式后端(如InMemoryBackend)max_requests:每个窗口内允许的最大请求数window_secs:窗口大小(秒)
Sourcepub fn in_memory(max_requests: u64, window_secs: u64) -> DistributedRateLimiter
pub fn in_memory(max_requests: u64, window_secs: u64) -> DistributedRateLimiter
使用内存后端创建分布式限流器(便捷方法)
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