touch_ratelimit 0.1.0

A composable, extensible rate limiting crate for Rust
Documentation
//! Tower middleware for rate limiting.
//!
//! This module provides the core Tower middleware components used to
//! enforce rate limiting in a framework-agnostic way.
//!
//! The middleware is composed of:
//! - [`RateLimitLayer`] — a middleware factory
//! - [`RateLimitService`] — per-request logic
//! - [`KeyExtractor`] — request-to-key mapping
//!
//! Framework-specific adapters (e.g. Axum) are built on top of this module.

pub mod error;
pub mod layer;
pub mod service;

/// Extracts a rate-limiting key from a request.
///
/// Implementations of this trait define how a request is mapped to a
/// logical identity (e.g. IP address, user ID, API key).
///
/// Returning `None` indicates that the request should not be rate-limited.
pub trait KeyExtractor<Req>: Send + Sync + 'static {
    /// Extract a rate-limiting key from the request.
    fn extract(&self, req: &Req) -> Option<String>;
}