[][src]Struct limitation::Limiter

pub struct Limiter { /* fields omitted */ }

A rate limiter using a fixed window counter, backed by Redis.

The per-period limit and the period duration are customizable when building an instance.

The count method is the primary unit of interaction which requires a key representing a user, a session, an interaction, etc. This method returns a Future which needs a runtime to drive the task to completion asynchronously.

Methods

impl Limiter[src]

pub fn build(redis_url: &str) -> Builder[src]

Returns a builder for a Limiter.

The finish method will build the final Limiter and perform a synchronous connection test to the Redis backend.

pub fn count<K: Into<String>>(
    &self,
    key: K
) -> impl Future<Item = Status, Error = Error>
[src]

Counts a request on a key over a period and returns a Status.

The Status type gives the caller a current state snapshot for the given key. If the limit is exceeded a Error::LimitExceeded will be returned which also contains a Status. Critically, the Status contains a time when the next period begins and the limit will reset. The time is a "unix timestamp" in UTC time.

Errors

Returns an Err if:

  • The limit has been exceeded in the current period
  • A client error has occurred
  • A time computation failed

Trait Implementations

impl Clone for Limiter[src]

impl Debug for Limiter[src]

Auto Trait Implementations

impl Send for Limiter

impl Sync for Limiter

impl Unpin for Limiter

impl UnwindSafe for Limiter

impl RefUnwindSafe for Limiter

Blanket Implementations

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.

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

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

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