pub struct TokenBucket { /* private fields */ }Expand description
A token bucket rate limiter
Implementations§
Source§impl TokenBucket
impl TokenBucket
Sourcepub fn new(capacity: f64, fill_rate: f64) -> Self
pub fn new(capacity: f64, fill_rate: f64) -> Self
Create a new token bucket
§Arguments
capacity- Maximum number of tokens the bucket can holdfill_rate- Number of tokens added to the bucket per second
Sourcepub async fn try_acquire(&self, amount: f64) -> bool
pub async fn try_acquire(&self, amount: f64) -> bool
Try to acquire tokens from the bucket
Returns true if tokens were acquired, false otherwise.
Trait Implementations§
Source§impl Clone for TokenBucket
impl Clone for TokenBucket
Source§fn clone(&self) -> TokenBucket
fn clone(&self) -> TokenBucket
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TokenBucket
impl !RefUnwindSafe for TokenBucket
impl Send for TokenBucket
impl Sync for TokenBucket
impl Unpin for TokenBucket
impl UnsafeUnpin 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