pub struct TokenBucket { /* private fields */ }
Expand description
Token bucket rate limiter
Implementations§
Source§impl TokenBucket
impl TokenBucket
Sourcepub fn new(config: RateLimiterConfig) -> Self
pub fn new(config: RateLimiterConfig) -> Self
Create a new token bucket with the given configuration
Sourcepub fn with_metrics(
config: RateLimiterConfig,
metrics: Arc<dyn Metrics>,
) -> Self
pub fn with_metrics( config: RateLimiterConfig, metrics: Arc<dyn Metrics>, ) -> Self
Create a new token bucket with metrics collection
Sourcepub fn set_enabled(&self, enabled: bool)
pub fn set_enabled(&self, enabled: bool)
Enable or disable the rate limiter
Sourcepub async fn acquire(&self, tokens: u64) -> Result<(), RateLimitError>
pub async fn acquire(&self, tokens: u64) -> Result<(), RateLimitError>
Acquire the specified number of tokens
Sourcepub fn get_metrics(&self) -> RateLimiterMetrics
pub fn get_metrics(&self) -> RateLimiterMetrics
Get comprehensive metrics
Sourcepub fn success_rate(&self) -> f64
pub fn success_rate(&self) -> f64
Get success rate as a percentage
Sourcepub fn rejection_rate(&self) -> f64
pub fn rejection_rate(&self) -> f64
Get rejection rate as a percentage
Sourcepub fn adjust_rate(&self, success: bool)
pub fn adjust_rate(&self, success: bool)
Adjust adaptive rate based on success/failure patterns
Sourcepub fn reset_adaptive_rate(&self)
pub fn reset_adaptive_rate(&self)
Reset adaptive rate to initial value
Sourcepub fn set_adaptive_rate(&self, rate: u64)
pub fn set_adaptive_rate(&self, rate: u64)
Set adaptive rate manually
Sourcepub fn is_healthy(&self) -> bool
pub fn is_healthy(&self) -> bool
Check if rate limiter is healthy
Auto Trait Implementations§
impl !Freeze for TokenBucket
impl !RefUnwindSafe for TokenBucket
impl Send for TokenBucket
impl Sync for TokenBucket
impl Unpin for TokenBucket
impl !UnwindSafe for TokenBucket
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