pub struct TokenBucket { /* private fields */ }Expand description
Token bucket rate limiter
The token bucket algorithm works by:
- Adding tokens at a fixed rate (rate per second)
- Consuming one token per task execution
- Allowing bursts up to the bucket capacity
This is the default and recommended rate limiter for most use cases.
Implementations§
Source§impl TokenBucket
impl TokenBucket
Trait Implementations§
Source§impl Debug for TokenBucket
impl Debug for TokenBucket
Source§impl RateLimiter for TokenBucket
impl RateLimiter for TokenBucket
Source§fn try_acquire(&mut self) -> bool
fn try_acquire(&mut self) -> bool
Try to acquire a permit to execute a task Read more
Source§fn time_until_available(&self) -> Duration
fn time_until_available(&self) -> Duration
Get the time until a permit will be available
Source§fn available_permits(&self) -> u32
fn available_permits(&self) -> u32
Get the current number of available permits
Source§fn config(&self) -> &RateLimitConfig
fn config(&self) -> &RateLimitConfig
Get current configuration
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