Skip to main content

bitgateway_client/
config.rs

1use std::net::IpAddr;
2
3use bon::Builder;
4
5pub const DEFAULT_PORTAL_URL: &str = "http://10.0.0.55";
6pub const DEFAULT_CAPTIVE_PORTAL_URL: &str = "http://www.bit.edu.cn";
7
8#[derive(Clone, Debug, PartialEq, Eq, Builder)]
9pub struct Config {
10    #[builder(default = DEFAULT_PORTAL_URL.to_string(), into)]
11    portal_url: String,
12    #[builder(default = DEFAULT_CAPTIVE_PORTAL_URL.to_string(), into)]
13    captive_portal_url: String,
14    ip: Option<IpAddr>,
15    #[builder(default)]
16    dumb_terminal: bool,
17}
18
19impl Default for Config {
20    fn default() -> Self {
21        Self::builder().build()
22    }
23}
24
25impl Config {
26    #[must_use]
27    pub fn portal_url(&self) -> &str {
28        &self.portal_url
29    }
30
31    #[must_use]
32    pub fn captive_portal_url(&self) -> &str {
33        &self.captive_portal_url
34    }
35
36    #[must_use]
37    pub const fn ip(&self) -> Option<IpAddr> {
38        self.ip
39    }
40
41    #[must_use]
42    pub const fn dumb_terminal(&self) -> bool {
43        self.dumb_terminal
44    }
45}