1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::{borrow::Cow, fmt, net::IpAddr};
#[derive(Clone, Debug, PartialEq)]
pub enum HostAddress<'host> {
IpAddr(IpAddr),
HostName(Cow<'host, str>),
}
impl<'host> fmt::Display for HostAddress<'host> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::IpAddr(ip_addr) => ip_addr.fmt(f),
Self::HostName(host_name) => host_name.fmt(f),
}
}
}
impl<'host> HostAddress<'host> {
pub fn into_static(&self) -> HostAddress<'static> {
match self {
Self::IpAddr(ip_addr) => HostAddress::IpAddr(*ip_addr),
Self::HostName(host_name) => {
HostAddress::HostName(Cow::Owned(host_name.clone().into_owned()))
}
}
}
}