pub struct TokenBucket { /* private fields */ }Expand description
Token-bucket rate-limit throttle.
Implementations§
Source§impl TokenBucket
impl TokenBucket
Sourcepub fn new(rate_bytes_per_sec: u64) -> Self
pub fn new(rate_bytes_per_sec: u64) -> Self
Construct a new throttle at rate_bytes_per_sec. The throttle’s clock
starts at construction time.
Sourcepub fn next_sleep(&self, bytes_done: u64) -> Duration
pub fn next_sleep(&self, bytes_done: u64) -> Duration
Inspect whether the loop is currently over-budget and, if so, return
the recommended sleep duration to converge to the rate. Returns
Duration::ZERO when the throttle is happy with current progress.
Sourcepub fn maybe_sleep(&self, bytes_done: u64) -> bool
pub fn maybe_sleep(&self, bytes_done: u64) -> bool
Sleep for the recommended interval if any. Returns true if a sleep
was performed, false if no sleep was needed.
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 (const: unstable) · 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