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 ratelimit::{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);
}

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.