1use std::time::Duration;
2
3#[derive(Debug, Clone, Default, PartialEq, Eq)]
4pub enum ThrottleStrategy {
5 #[default]
7 Delay,
8 Reject,
10 Drop,
12}
13
14#[derive(Debug, Clone)]
15pub struct ThrottlerConfig {
16 pub max_requests: usize,
18 pub period: Duration,
20 pub strategy: ThrottleStrategy,
22}
23
24impl ThrottlerConfig {
25 pub fn new(max_requests: usize, period: Duration) -> Self {
26 Self {
27 max_requests,
28 period,
29 strategy: ThrottleStrategy::default(),
30 }
31 }
32
33 pub fn strategy(mut self, s: ThrottleStrategy) -> Self {
34 self.strategy = s;
35 self
36 }
37}