[−][src]Struct leaky_bucket_lite::LeakyBucket
The leaky bucket.
Implementations
impl LeakyBucket
[src]
pub fn builder() -> Builder
[src]
Construct a new leaky bucket through a builder.
pub fn max(&self) -> usize
[src]
Get the max number of tokens this rate limiter is configured for.
pub async fn acquire_one(&self) -> Result<(), Error>
[src]
Acquire a single token.
This is identical to acquire
with an argument of 1
.
Example
use leaky_bucket_lite::LeakyBucket; use std::{error::Error, time::Duration}; #[tokio::main] async fn main() -> Result<(), Box<dyn Error>> { let rate_limiter = LeakyBucket::builder() .max(5) .tokens(0) .refill_interval(Duration::from_secs(5)) .refill_amount(1) .build(); println!("Waiting for permit..."); // should take about 5 seconds to acquire. rate_limiter.acquire_one().await?; println!("I made it!"); Ok(()) }
pub async fn acquire(&self, amount: usize) -> Result<(), Error>
[src]
Acquire the given amount
of tokens.
Example
use leaky_bucket_lite::LeakyBucket; use std::{error::Error, time::Duration}; #[tokio::main] async fn main() -> Result<(), Box<dyn Error>> { let rate_limiter = LeakyBucket::builder() .max(5) .tokens(0) .refill_interval(Duration::from_secs(5)) .refill_amount(1) .build(); println!("Waiting for permit..."); // should take about 25 seconds to acquire. rate_limiter.acquire(5).await?; println!("I made it!"); Ok(()) }
Trait Implementations
impl Clone for LeakyBucket
[src]
pub fn clone(&self) -> LeakyBucket
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for LeakyBucket
[src]
Auto Trait Implementations
impl !RefUnwindSafe for LeakyBucket
[src]
impl Send for LeakyBucket
[src]
impl Sync for LeakyBucket
[src]
impl Unpin for LeakyBucket
[src]
impl !UnwindSafe for LeakyBucket
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,