whois_rust/
who_is_host.rs1use validators::prelude::*;
2use validators_prelude::Host;
3
4#[derive(Debug, Clone, PartialEq, Eq, Hash, Validator)]
6#[validator(host)]
7pub struct WhoIsHost {
8 pub(crate) host: Host,
9 pub(crate) port: Option<u16>,
10}
11
12impl WhoIsHost {
13 #[inline]
15 pub const fn host(&self) -> &Host {
16 &self.host
17 }
18
19 #[inline]
21 pub const fn port(&self) -> Option<u16> {
22 self.port
23 }
24
25 pub(crate) fn to_addr_string(&self, default_port: u16) -> String {
26 let port = self.port.unwrap_or(default_port);
27
28 match &self.host {
29 Host::IPv4(ip) => format!("{}:{}", ip, port),
30 Host::IPv6(ip) => format!("[{}]:{}", ip, port),
31 Host::Domain(domain) => format!("{}:{}", domain, port),
32 }
33 }
34}