pub struct RateLimiter { /* private fields */ }Expand description
Main rate limiter
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(config: RateLimitConfig) -> Self
pub fn new(config: RateLimitConfig) -> Self
Create a new rate limiter
Sourcepub fn with_cost_estimator(
config: RateLimitConfig,
estimator: QueryCostEstimator,
) -> Self
pub fn with_cost_estimator( config: RateLimitConfig, estimator: QueryCostEstimator, ) -> Self
Create with custom cost estimator
Sourcepub fn check(&self, key: &LimiterKey, cost: u32) -> RateLimitResult
pub fn check(&self, key: &LimiterKey, cost: u32) -> RateLimitResult
Check rate limit for a key
Sourcepub fn check_with_priority(
&self,
key: &LimiterKey,
cost: u32,
priority: PriorityLevel,
) -> RateLimitResult
pub fn check_with_priority( &self, key: &LimiterKey, cost: u32, priority: PriorityLevel, ) -> RateLimitResult
Check rate limit with priority
Sourcepub fn check_concurrency(
&self,
key: &LimiterKey,
) -> Result<Arc<ConcurrencyLimiter>, RateLimitExceeded>
pub fn check_concurrency( &self, key: &LimiterKey, ) -> Result<Arc<ConcurrencyLimiter>, RateLimitExceeded>
Check and acquire concurrency slot
Sourcepub fn check_query(&self, key: &LimiterKey, query: &str) -> RateLimitResult
pub fn check_query(&self, key: &LimiterKey, query: &str) -> RateLimitResult
Check for a query with automatic cost estimation
Sourcepub fn check_query_with_priority(
&self,
key: &LimiterKey,
query: &str,
priority: PriorityLevel,
) -> RateLimitResult
pub fn check_query_with_priority( &self, key: &LimiterKey, query: &str, priority: PriorityLevel, ) -> RateLimitResult
Check query with priority
Sourcepub fn check_all(&self, keys: &[LimiterKey], cost: u32) -> RateLimitResult
pub fn check_all(&self, keys: &[LimiterKey], cost: u32) -> RateLimitResult
Check multiple keys (returns first failure)
Sourcepub fn reset(&self, key: &LimiterKey)
pub fn reset(&self, key: &LimiterKey)
Reset limits for a key
Sourcepub fn get_key_stats(&self, key: &LimiterKey) -> HashMap<String, u64>
pub fn get_key_stats(&self, key: &LimiterKey) -> HashMap<String, u64>
Get current stats for a key
Sourcepub fn metrics(&self) -> Arc<RateLimitMetrics> ⓘ
pub fn metrics(&self) -> Arc<RateLimitMetrics> ⓘ
Get metrics
Sourcepub fn update_config(&self, config: RateLimitConfig)
pub fn update_config(&self, config: RateLimitConfig)
Update configuration
Sourcepub fn config(&self) -> RateLimitConfig
pub fn config(&self) -> RateLimitConfig
Get current configuration (cloned)
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for RateLimiter
impl !RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnsafeUnpin for RateLimiter
impl !UnwindSafe 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
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