Skip to main content

RateLimitStore

Trait RateLimitStore 

Source
pub trait RateLimitStore:
    Send
    + Sync
    + 'static {
    // Required method
    fn hit<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        limit: u32,
        window: Duration,
        sliding: bool,
    ) -> Pin<Box<dyn Future<Output = Decision> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Where request counts live. The default is process memory; implement it (or use RedisRateLimitStore, feature redis) to share limits between instances.

A store decides by itself what to do when its backend fails; the Redis one lets requests through.

Required Methods§

Source

fn hit<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, limit: u32, window: Duration, sliding: bool, ) -> Pin<Box<dyn Future<Output = Decision> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Count one request for key against limit per window

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§