pub struct RateLimiter { /* private fields */ }Expand description
Token bucket rate limiter
Allows bursts up to the bucket size, then rate limits to the configured RPS.
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(config: RateLimitConfig) -> Self
pub fn new(config: RateLimitConfig) -> Self
Create a new rate limiter with the given configuration
Sourcepub async fn acquire(&self)
pub async fn acquire(&self)
Acquire a token, waiting if necessary
Returns immediately if a token is available, otherwise waits until a token becomes available.
Sourcepub async fn try_acquire(&self) -> bool
pub async fn try_acquire(&self) -> bool
Try to acquire a token without waiting
Returns true if a token was acquired, false if rate limited.
Sourcepub async fn available_tokens(&self) -> u32
pub async fn available_tokens(&self) -> u32
Get current available tokens (for monitoring)
Trait Implementations§
Source§impl Clone for RateLimiter
impl Clone for RateLimiter
Source§impl Debug for RateLimiter
impl Debug for RateLimiter
Auto Trait Implementations§
impl Freeze for RateLimiter
impl !RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin 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