Skip to main content

RateLimitBackend

Trait RateLimitBackend 

Source
pub trait RateLimitBackend:
    Send
    + Sync
    + 'static {
    // Required method
    fn check(
        &self,
        key: &str,
        quota: &Quota,
    ) -> impl Future<Output = RateLimitResult> + Send;
}
Expand description

Backend trait for rate limit state storage.

Uses native async fn in trait (MSRV 1.85) instead of #[async_trait], so a check dispatches no future boxing and no vtable call. The returned future is required to be Send so backends work on multi-threaded runtimes (the Tower layer’s boxed future, spawned tasks).

The trait is intentionally not dyn-compatible: every consumer in this crate is generic over B: RateLimitBackend, keeping the hot path statically dispatched. If you need heterogeneous backend sets, wrap them in your own enum rather than a dyn trait object.

Required Methods§

Source

fn check( &self, key: &str, quota: &Quota, ) -> impl Future<Output = RateLimitResult> + Send

Check if a request for key is allowed under the given quota.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl RateLimitBackend for InMemoryBackend

Available on crate feature in-memory only.
Source§

impl RateLimitBackend for NoopBackend

Available on crate feature test-util only.
Source§

impl RateLimitBackend for RedisBackend

Available on crate feature redis only.
Source§

impl RateLimitBackend for SlidingWindowBackend

Available on crate feature sliding-window only.
Source§

impl RateLimitBackend for SqliteBackend

Available on crate feature sqlite only.