tower_rate_limit_fred/
key_resolver.rs

1use fred::types::Key;
2use http::{Request, Response};
3
4/// Resolves a Redis key for each incoming request.
5///
6/// Requests with the same key are rate limited together.
7pub trait KeyResolver: Clone {
8    /// The type of the response body when [`KeyResolver::key`] fails.
9    /// Must match the type of the response body of the underlying service.
10    type ErrorBody;
11
12    /// Attempts to resolve a key given the request, returning a custom response if unsuccessful.
13    fn key<T>(&self, req: &Request<T>) -> Result<Key, Response<Self::ErrorBody>>;
14}