Skip to main content

RateLimiter

Trait RateLimiter 

Source
pub trait RateLimiter:
    Send
    + Sync
    + 'static {
    // Required method
    fn check<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        key: &'life1 RateLimitKey<'life2>,
    ) -> Pin<Box<dyn Future<Output = RateLimitDecision> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Transport-agnostic rate-limit contract.

Implementations MUST be Send + Sync + 'static so consumer binders can wrap them in a shared Arc<dyn RateLimiter> inside their middleware stack.

Required Methods§

Source

fn check<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 RateLimitKey<'life2>, ) -> Pin<Box<dyn Future<Output = RateLimitDecision> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Check and record a single hit for key. Returns RateLimitDecision::Allow if the request is permitted (and records the hit), or RateLimitDecision::Deny otherwise (without recording).

Implementors§