tlq_client/
config.rs

1use std::time::Duration;
2
3#[derive(Debug, Clone)]
4pub struct Config {
5    pub host: String,
6    pub port: u16,
7    pub timeout: Duration,
8    pub max_retries: u32,
9    pub retry_delay: Duration,
10}
11
12impl Default for Config {
13    fn default() -> Self {
14        Self {
15            host: "localhost".to_string(),
16            port: 1337,
17            timeout: Duration::from_secs(30),
18            max_retries: 3,
19            retry_delay: Duration::from_millis(100),
20        }
21    }
22}
23
24pub struct ConfigBuilder {
25    config: Config,
26}
27
28impl ConfigBuilder {
29    pub fn new() -> Self {
30        Self {
31            config: Config::default(),
32        }
33    }
34
35    pub fn host(mut self, host: impl Into<String>) -> Self {
36        self.config.host = host.into();
37        self
38    }
39
40    pub fn port(mut self, port: u16) -> Self {
41        self.config.port = port;
42        self
43    }
44
45    pub fn timeout(mut self, timeout: Duration) -> Self {
46        self.config.timeout = timeout;
47        self
48    }
49
50    pub fn timeout_ms(mut self, ms: u64) -> Self {
51        self.config.timeout = Duration::from_millis(ms);
52        self
53    }
54
55    pub fn max_retries(mut self, retries: u32) -> Self {
56        self.config.max_retries = retries;
57        self
58    }
59
60    pub fn retry_delay(mut self, delay: Duration) -> Self {
61        self.config.retry_delay = delay;
62        self
63    }
64
65    pub fn retry_delay_ms(mut self, ms: u64) -> Self {
66        self.config.retry_delay = Duration::from_millis(ms);
67        self
68    }
69
70    pub fn build(self) -> Config {
71        self.config
72    }
73}
74
75impl Default for ConfigBuilder {
76    fn default() -> Self {
77        Self::new()
78    }
79}