arcbox_helper/validate/
dns_port.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub struct DnsPort(u16);
4
5impl DnsPort {
6 pub fn value(self) -> u16 {
7 self.0
8 }
9}
10
11impl TryFrom<u16> for DnsPort {
12 type Error = String;
13
14 fn try_from(port: u16) -> Result<Self, Self::Error> {
15 if port < 1024 {
16 return Err(format!("port {port} is below 1024 (privileged range)"));
17 }
18 Ok(Self(port))
19 }
20}
21
22impl std::fmt::Display for DnsPort {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 write!(f, "{}", self.0)
25 }
26}