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