RateLimiterKeyed

Trait RateLimiterKeyed 

Source
pub trait RateLimiterKeyed<K>: Sync
where K: Hash + Eq + Send + Sync,
{ // Required methods fn acquire<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 K, ) -> Pin<Box<dyn Future<Output = Token> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn acquire_timeout<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 K, duration: Duration, ) -> Pin<Box<dyn Future<Output = Option<Token>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn release<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 K, token: Token, outcome: Option<RequestOutcome>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; }
Expand description

Controls the rate of requests over time with per-key rate limiting.

Each key maintains its own rate limit state, allowing for independent rate limiting across different clients, users, or request types.

Required Methods§

Source

fn acquire<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 K, ) -> Pin<Box<dyn Future<Output = Token> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Acquire permission to make a request for a specific key. Waits until a token is available.

Source

fn acquire_timeout<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 K, duration: Duration, ) -> Pin<Box<dyn Future<Output = Option<Token>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Acquire permission to make a request for a specific key with a timeout. Returns a token if successful.

Source

fn release<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 K, token: Token, outcome: Option<RequestOutcome>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Release the token and record the outcome of the request for the specific key. The response time is calculated from when the token was acquired.

Implementors§

Source§

impl<T, K, F> RateLimiterKeyed<K> for DefaultRateLimiterKeyed<T, K, F>
where T: RateLimitAlgorithm + Send + Sync + Debug, K: Hash + Eq + Clone + Send + Sync, F: Fn() -> T + Send + Sync,