DistributedRateLimiter

Trait DistributedRateLimiter 

Source
pub trait DistributedRateLimiter: Send + Sync {
    // Required methods
    fn try_acquire<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn time_until_available<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Duration>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn available_permits<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<u32>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn reset<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn set_rate<'life0, 'async_trait>(
        &'life0 self,
        rate: f64,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn config(&self) -> &RateLimitConfig;
    fn backend_name(&self) -> &str;
}
Expand description

Trait for distributed rate limiter backends

Implementations should provide atomic operations for rate limiting across multiple processes/workers.

Required Methods§

Source

fn try_acquire<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Try to acquire a permit atomically

Returns Ok(true) if acquired, Ok(false) if rate limited, or an error if the backend is unavailable.

Source

fn time_until_available<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Duration>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the time until a permit will be available

Returns Ok(Duration) with the wait time, or an error if unavailable.

Source

fn available_permits<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u32>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the current number of available permits

Returns Ok(count) or an error if unavailable.

Source

fn reset<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reset the distributed rate limiter

Clears all state in the distributed backend.

Source

fn set_rate<'life0, 'async_trait>( &'life0 self, rate: f64, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Update the rate limit configuration

Note: This updates the local configuration. Distributed backends may need additional coordination to sync configuration changes.

Source

fn config(&self) -> &RateLimitConfig

Get current configuration

Source

fn backend_name(&self) -> &str

Get the backend name (for diagnostics)

Implementors§