ai_lib/rate_limiter/
config.rs

1//! Rate limiter configuration
2
3use serde::{Deserialize, Serialize};
4
5/// Configuration for rate limiting behavior
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct RateLimiterConfig {
8    /// Maximum requests per second
9    pub requests_per_second: u64,
10    /// Burst capacity for handling traffic spikes
11    pub burst_capacity: u64,
12    /// Whether to use adaptive rate limiting
13    pub adaptive: bool,
14    /// Initial rate for adaptive mode
15    pub initial_rate: Option<u64>,
16}
17
18impl Default for RateLimiterConfig {
19    fn default() -> Self {
20        Self {
21            requests_per_second: 10,
22            burst_capacity: 20,
23            adaptive: false,
24            initial_rate: None,
25        }
26    }
27}
28
29impl RateLimiterConfig {
30    /// Create a production-ready configuration
31    pub fn production() -> Self {
32        Self {
33            requests_per_second: 5,
34            burst_capacity: 10,
35            adaptive: true,
36            initial_rate: Some(5),
37        }
38    }
39
40    /// Create a development configuration with higher limits
41    pub fn development() -> Self {
42        Self {
43            requests_per_second: 20,
44            burst_capacity: 50,
45            adaptive: false,
46            initial_rate: None,
47        }
48    }
49
50    /// Create a conservative configuration for rate-limited providers
51    pub fn conservative() -> Self {
52        Self {
53            requests_per_second: 2,
54            burst_capacity: 5,
55            adaptive: true,
56            initial_rate: Some(1),
57        }
58    }
59}