pub struct RateLimitConfig {
pub limiter: Arc<dyn RateLimiter + Send + Sync>,
pub key_extractor: KeyExtractor,
pub exclude_paths: Vec<String>,
pub key_prefix: String,
}Expand description
RateLimit 中间件配置
必须通过 RateLimitConfig::new() 构造,传入一个 RateLimiter 实例(用 Arc 包裹)。
可通过 with_* 链式 builder 方法配置 Key 提取策略、排除路径、Key 前缀。
Fields§
§limiter: Arc<dyn RateLimiter + Send + Sync>限流器实例(Arc<dyn RateLimiter + Send + Sync> 共享)
key_extractor: KeyExtractorKey 提取策略(默认 Ip)
exclude_paths: Vec<String>排除路径(不进行限流,复用 crate::middleware::auth::is_route_allowed 匹配)
key_prefix: StringKey 前缀(用于区分不同限流场景,如 "login" / "api" / "sms")
Implementations§
Source§impl RateLimitConfig
impl RateLimitConfig
Sourcepub fn with_key_extractor(self, extractor: KeyExtractor) -> Self
pub fn with_key_extractor(self, extractor: KeyExtractor) -> Self
设置 Key 提取策略
Sourcepub fn with_exclude_paths(self, paths: Vec<String>) -> Self
pub fn with_exclude_paths(self, paths: Vec<String>) -> Self
设置排除路径
Sourcepub fn with_key_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_key_prefix(self, prefix: impl Into<String>) -> Self
设置 Key 前缀(用于区分不同限流场景)
Sourcepub fn is_excluded(&self, path: &str) -> bool
pub fn is_excluded(&self, path: &str) -> bool
判断路径是否被排除
Trait Implementations§
Source§impl Clone for RateLimitConfig
impl Clone for RateLimitConfig
Source§fn clone(&self) -> RateLimitConfig
fn clone(&self) -> RateLimitConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for RateLimitConfig
impl !UnwindSafe for RateLimitConfig
impl Freeze for RateLimitConfig
impl Send for RateLimitConfig
impl Sync for RateLimitConfig
impl Unpin for RateLimitConfig
impl UnsafeUnpin for RateLimitConfig
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.