pub struct LocalLimiter { /* private fields */ }Expand description
A thread-safe limiter built on Atomics. It’s base unit is in seconds, i.e. the minimum allowed rate is 1 per second. Internally the limiter works with the system time granularity, i.e. nanoseconds on unix and milliseconds on windows. The implementation is a sliding window: every time the limiter is increased, the amount of time that has passed is also refilled.
Implementations§
Source§impl LocalLimiter
impl LocalLimiter
Sourcepub fn with_granularity(seconds: u32) -> LocalLimiter
pub fn with_granularity(seconds: u32) -> LocalLimiter
Allows setting a custom time granularity. The default() implementation is 1 second.
Trait Implementations§
Source§impl Default for LocalLimiter
impl Default for LocalLimiter
Source§impl Limiter for LocalLimiter
impl Limiter for LocalLimiter
Source§fn inc(&self, limit: u32) -> bool
fn inc(&self, limit: u32) -> bool
Takes the limit per interval.
Returns false if the limit is exceeded, otherwise true.
Source§fn rate(&self) -> f64
fn rate(&self) -> f64
Returns the effective rate per interval.
Note: The rate is only guaranteed to be accurate immediately after a call to inc().
Source§fn update_rate(&self) -> f64
fn update_rate(&self) -> f64
Updates the rate and returns it
Auto Trait Implementations§
impl !Freeze for LocalLimiter
impl RefUnwindSafe for LocalLimiter
impl Send for LocalLimiter
impl Sync for LocalLimiter
impl Unpin for LocalLimiter
impl UnsafeUnpin for LocalLimiter
impl UnwindSafe for LocalLimiter
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