1#[derive(Debug, Clone)]
18pub struct ResolverConfig {
19 pub domain: String,
22
23 pub nameserver: String,
25
26 pub port: u16,
29
30 pub search_order: u32,
32}
33
34impl ResolverConfig {
35 #[must_use]
37 pub fn new(domain: impl Into<String>, nameserver: impl Into<String>, port: u16) -> Self {
38 Self {
39 domain: domain.into(),
40 nameserver: nameserver.into(),
41 port,
42 search_order: 1,
43 }
44 }
45
46 #[must_use]
48 pub const fn with_search_order(mut self, order: u32) -> Self {
49 self.search_order = order;
50 self
51 }
52
53 #[must_use]
55 pub fn arcbox_default(port: u16) -> Self {
56 Self::new("arcbox.local", "127.0.0.1", port)
57 }
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn new_sets_defaults() {
66 let c = ResolverConfig::new("test.local", "127.0.0.1", 5553);
67 assert_eq!(c.domain, "test.local");
68 assert_eq!(c.nameserver, "127.0.0.1");
69 assert_eq!(c.port, 5553);
70 assert_eq!(c.search_order, 1);
71 }
72
73 #[test]
74 fn with_search_order() {
75 let c = ResolverConfig::new("x.local", "127.0.0.1", 53).with_search_order(10);
76 assert_eq!(c.search_order, 10);
77 }
78
79 #[test]
80 fn arcbox_default() {
81 let c = ResolverConfig::arcbox_default(5553);
82 assert_eq!(c.domain, "arcbox.local");
83 assert_eq!(c.nameserver, "127.0.0.1");
84 assert_eq!(c.port, 5553);
85 }
86}