[][src]Struct simple_rate_limit::RateLimiter

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

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

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.