[−][src]Struct simple_rate_limit::RateLimiter
A RateLimiter
enforces a RateLimit
by maintaining a ring
vector of timestamps capped at the RateLimit::count
.
Fields
limit: RateLimit
Implementations
impl RateLimiter
[src]
pub fn new(limit: RateLimit) -> RateLimiter
[src]
Creates a new RateLimiter
without preallocating
storage. Ideal if you might never use it.
pub fn new_preallocated(limit: RateLimit) -> RateLimiter
[src]
Creates a new RateLimiter
with preallocated storage. Ideal
if you're likely to use it a lot to avoid resizing during fill.
pub fn check(&mut self) -> bool
[src]
Logs the current time with the RateLimiter
and checks if
the event falls within the rate limit.
pub fn check_at(&mut self, instant: Instant) -> bool
[src]
Like check
, but you can provide an arbitrary timestamp
(useful for tests!). Promise that you'll only march forwards
in time and we promise to return the correct answers.
pub fn sweep(&mut self, instant: Instant) -> bool
[src]
Removes all the readings from longer than the contained
RateLimit
's period ago, relative to the provided instant.
Auto Trait Implementations
impl RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnwindSafe for RateLimiter
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,
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, 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.
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>,