use async_trait::async_trait;
use std::time::Duration;
use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Quota {
pub limit: u32,
pub remaining: u32,
pub reset: Duration,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Decision {
pub ok: bool,
pub retry_after: Option<Duration>,
pub quota: Option<Quota>,
}
#[derive(Debug, Clone, Error)]
pub enum RateLimitError {
#[error("rate limiter transport error: {0}")]
Transport(String),
}
#[async_trait]
pub trait RateLimiter: Send + Sync {
async fn limit(&self, key: &str) -> Result<Decision, RateLimitError>;
}