pub struct LocalRateLimiterProvider { /* private fields */ }trypema only.Expand description
Provider for in-process rate limiting strategies.
Exposes AbsoluteLocalRateLimiter and SuppressedLocalRateLimiter under one shared
configuration.
§Strategies
- Absolute: Best-effort sliding-window allow/reject admission
- Suppressed: Probabilistic suppression for graceful degradation
§Thread Safety
All strategies are thread-safe and designed for concurrent use.
§Examples
use trypema::RateLimit;
let rate = RateLimit::per_second(10.0).unwrap();
let abs_decision = rl.absolute().inc("user_123", &rate, 1);
let sup_decision = rl.suppressed().inc("user_456", &rate, 1);Implementations§
Source§impl LocalRateLimiterProvider
impl LocalRateLimiterProvider
Sourcepub fn builder() -> LocalRateLimiterBuilder
pub fn builder() -> LocalRateLimiterBuilder
Create builder using default validated configuration.
Sourcepub fn start_cleanup_loop(self: &Arc<LocalRateLimiterProvider>)
pub fn start_cleanup_loop(self: &Arc<LocalRateLimiterProvider>)
Start stale-state cleanup. Calling while already running is no-op.
Sourcepub fn stop_cleanup_loop(&self)
pub fn stop_cleanup_loop(&self)
Stop stale-state cleanup. Calling while stopped is no-op.
Sourcepub fn absolute(&self) -> &AbsoluteLocalRateLimiter
pub fn absolute(&self) -> &AbsoluteLocalRateLimiter
Access the absolute strategy.
Returns the absolute local limiter. Admission is allow/reject and best-effort under concurrency; concurrent callers may temporarily overshoot.
See AbsoluteLocalRateLimiter for full documentation.
§Examples
use trypema::{RateLimit, RateLimitDecision};
let rate = RateLimit::per_second(10.0).unwrap();
let decision = rl.absolute().inc("user_123", &rate, 1);
assert!(matches!(decision, RateLimitDecision::Allowed));Sourcepub fn suppressed(&self) -> &SuppressedLocalRateLimiter
pub fn suppressed(&self) -> &SuppressedLocalRateLimiter
Access the suppressed strategy.
Returns a reference to the suppressed local rate limiter, which provides probabilistic suppression for graceful degradation under load.
Returns RateLimitDecision::Suppressed
with suppression metadata.
See SuppressedLocalRateLimiter for full documentation.
§Examples
use trypema::{RateLimit, RateLimitDecision};
let rate = RateLimit::per_second(10.0).unwrap();
match rl.suppressed().inc("user_123", &rate, 1) {
RateLimitDecision::Suppressed { is_allowed, suppression_factor, .. } => {
println!("suppression: {suppression_factor}, allowed: {is_allowed}");
}
RateLimitDecision::Allowed => {}
RateLimitDecision::Rejected { .. } => unreachable!(),
}