pub struct Ratelimit {
slice_start_time: Instant,
slice_end_time: Instant,
slice_quota: u64,
slice_ns: Duration,
dispatched: u64,
}
Fields§
§slice_start_time: Instant
§slice_end_time: Instant
§slice_quota: u64
§slice_ns: Duration
§dispatched: u64
Implementations§
source§impl Ratelimit
impl Ratelimit
pub fn new() -> Self
pub fn ratelimit_set_speed(&mut self, speed: u64)
sourcepub fn ratelimit_calculate_delay(&mut self, n: u64) -> u64
pub fn ratelimit_calculate_delay(&mut self, n: u64) -> u64
Calculate and return delay for next request in ns Record that we sent n data units (where n matches the scale chosen during ratelimit_set_speed).If we may send more data units in the current time slice, return 0 (i.e. no delay). Otherwise return the amount of time (in ns) until the start of the next time slice that will permit sending the next chunk of data.
Recording sent data units even after exceeding the quota is permitted; the time slice will be extended accordingly.
Auto Trait Implementations§
impl Freeze for Ratelimit
impl RefUnwindSafe for Ratelimit
impl Send for Ratelimit
impl Sync for Ratelimit
impl Unpin for Ratelimit
impl UnwindSafe for Ratelimit
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.