oni_comb_uri_rs/models/
host_name.rs

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
32
33
34
35
36
37
38
39
40
use std::fmt::Formatter;
use std::net::{Ipv4Addr, Ipv6Addr};

#[derive(Debug, Clone, PartialEq, Hash)]
pub enum HostName {
  RegName(String),
  Ipv4Address(Ipv4Addr),
  IpLiteral(IpLiteral),
}

#[derive(Debug, Clone, PartialEq, Hash)]
pub enum IpLiteral {
  Ipv6Address(Ipv6Addr),
  IpvFuture(String),
}

impl std::fmt::Display for IpLiteral {
  fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
    match self {
      IpLiteral::Ipv6Address(ip) => write!(f, "[{}]", ip),
      IpLiteral::IpvFuture(future) => write!(f, "[{}]", future),
    }
  }
}

impl Default for HostName {
  fn default() -> Self {
    HostName::RegName(String::default())
  }
}

impl std::fmt::Display for HostName {
  fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
    match self {
      HostName::RegName(reg_name) => write!(f, "{}", reg_name),
      HostName::Ipv4Address(ipv4_addr) => write!(f, "{}", ipv4_addr),
      HostName::IpLiteral(ip_literal) => write!(f, "{}", ip_literal),
    }
  }
}