Skip to main content

RateLimitStore

Trait RateLimitStore 

Source
pub trait RateLimitStore:
    Send
    + Sync
    + 'static {
    // Required method
    fn consume<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        config: RateLimitConfig,
    ) -> Pin<Box<dyn Future<Output = Result<RateLimitDecision, CoolError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
}
Expand description

Pluggable storage for token-bucket state. Implementations must be safe to share across tasks (use a Mutex internally, or rely on the backing store’s atomicity).

Required Methods§

Source

fn consume<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, config: RateLimitConfig, ) -> Pin<Box<dyn Future<Output = Result<RateLimitDecision, CoolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Atomically consume one token for key. Returns the decision based on the bucket state after the consumption attempt.

Implementors§