[][src]Struct simple_rate_limit::RateLimiter

pub struct RateLimiter {
    pub limit: RateLimit,
    // some fields omitted

Enforces a RateLimit by maintaining a ring vector of timestamps capped at the RateLimit::count.


limit: RateLimit


impl RateLimiter[src]

pub fn new(limit: RateLimit) -> RateLimiter[src]

Create without preallocating storage. Ideal if it may go unused.

pub fn new_preallocated(limit: RateLimit) -> RateLimiter[src]

Create 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]

Checks whether we're able to perform the event at this time. On success, logs the current time to count towards future enforcement.

pub fn check_at(&mut self, instant: Instant) -> bool[src]

Like RateLimiter::check, but you can provide an arbitrary timestamp (useful for tests!).

Warning: do not go backwards in time, things will mess up.

pub fn sweep(&mut self, instant: Instant) -> bool[src]

Removes all readings before the period of our RateLimit, relative to the provided Instant.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.