[−][src]Struct limitation::Limiter
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]
&self,
key: K
) -> impl Future<Item = Status, Error = Error>
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
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]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,