pub struct RateLimiter { /* private fields */ }Expand description
A rate limiter that returns the wait duration for limitation.
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(rate: f64) -> Self
pub fn new(rate: f64) -> Self
Create a rate limiter that returns the wait duration for limitation.
Sourcepub fn consume(&self, weight: f64) -> Duration
pub fn consume(&self, weight: f64) -> Duration
Consume some quota from the rate limiter.
If there is not enough quota left, return a duration for the caller to wait.
Otherwise, return Duration::ZERO indicating no need to wait.
Trait Implementations§
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