use async_trait::async_trait; use thiserror::Error; #[derive(Debug, Error)] pub enum ThrottleError { #[error("error-smokesignal-throttle-1 Redis error: {0}")] RedisError(String), #[error("error-smokesignal-throttle-2 Time error: {0}")] TimeError(String), } /// Trait for throttling actions by key /// /// Implementations can use different strategies (sliding window, token bucket, etc.) /// to limit the rate of actions for a given key. #[async_trait] pub trait Throttle: Send + Sync { /// Check if an action is allowed for the given key, and if so, record it /// /// Returns true if the action is allowed, false if throttled async fn check_and_record(&self, key: &str) -> Result; /// Check if an action is allowed for the given key without recording /// /// Returns true if the action would be allowed, false if it would be throttled async fn check(&self, key: &str) -> Result; }