#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct IPv6Address {
pub chunks: [u16; 8],
}
impl IPv6Address {
pub const UNSPECIFIED: IPv6Address =
IPv6Address::new(0, 0, 0, 0, 0, 0, 0, 0);
pub const LOCALHOST: IPv6Address =
IPv6Address::new(0, 0, 0, 0, 0, 0, 0, 1);
}
impl IPv6Address {
pub const fn new(
a: u16, b: u16, c: u16, d: u16,
e: u16, f: u16, g: u16, h: u16)
-> IPv6Address {
IPv6Address{ chunks: [a, b, c, d, e, f, g, h] }
}
}
impl IPv6Address {
pub fn is_unspecified(&self) -> bool {
self == &IPv6Address::UNSPECIFIED
}
pub fn is_loopback(&self) -> bool {
self == &IPv6Address::LOCALHOST
}
}
impl ToString for IPv6Address {
fn to_string(&self) -> String {
use std::net::Ipv6Addr;
Ipv6Addr::from(self.chunks).to_string()
}
}