Skip to main content

Crate throttle_kit

Crate throttle_kit 

Source
Expand description

Rate limiting for Rust.

Implements the GCRA (Generic Cell Rate Algorithm) with pluggable backends (in-memory via DashMap, optional Redis) and optional Tower layer integration.

§Quick Start

use throttle_kit::{RateLimiter, Quota, InMemoryBackend};

#[tokio::main]
async fn main() {
    let backend = InMemoryBackend::new();
    let limiter = RateLimiter::new(
        Quota::per_second(10),
        backend,
    );

    let result = limiter.check("user-123").await;
    assert!(result.allowed);
}

§Client identity (tower feature)

The Tower layer keys requests by the client’s socket address by default and ignores X-Forwarded-For (secure by default). Behind proxies you control, configure ClientIpConfig; see the [client_ip] module docs for the resolution algorithm and the README for axum wiring (.into_make_service_with_connect_info).

Structs§

InMemoryBackend
In-memory backend backed by a DashMap.
KeyedRateLimiter
Per-key rate limiter that tracks separate rate limits for each key.
Quota
A rate limit quota expressed in the GCRA style.
RateLimitResult
Result of a rate limit check.
RateLimiter
Core rate limiter that delegates to a RateLimitBackend.

Enums§

RateLimitError
Errors returned by the rate limiter.

Traits§

RateLimitBackend
Backend trait for rate limit state storage.