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
use std::fmt;
use std::net::IpAddr;

#[derive(Debug)]
pub struct Hostname {
  pub domain: String,
  pub ip: IpAddr,
  pub enabled: bool,
  // TODO: ip_v6: bool
}

impl Hostname {
  fn new(domain: &str, ip: IpAddr, enabled: bool) -> Hostname {
    Hostname {
      domain: String::from(domain),
      ip,
      enabled,
    }
  }
}

// impl fmt::Display for Hostname {
//   fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
//     self.ip.fmt(fmt);
//     Ok(())
//   }
// }

#[test]
fn test_hostname_new() {
  println!(
    "{:?}",
    Hostname::new("a.xiaomawang.com", "127.0.0.1".parse().unwrap(), true)
  )
}