Skip to main content

cratefield_core/ports/
rate_limiter.rs

1//! The `RateLimiter` port (architecture section 5).
2
3use async_trait::async_trait;
4use std::time::Duration;
5use thiserror::Error;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct Decision {
9    pub ok: bool,
10    pub retry_after: Option<Duration>,
11}
12
13#[derive(Debug, Clone, Error)]
14pub enum RateLimitError {
15    #[error("rate limiter transport error: {0}")]
16    Transport(String),
17}
18
19#[async_trait]
20pub trait RateLimiter: Send + Sync {
21    async fn limit(&self, key: &str) -> Result<Decision, RateLimitError>;
22}