net_lattice_model/
address.rs1use std::fmt;
2
3use net_lattice_ip::{Ipv4Address, Ipv4Network, Ipv6Address, Ipv6Network};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub enum IpAddress {
13 V4(Ipv4Address),
14 V6(Ipv6Address),
15}
16
17impl From<Ipv4Address> for IpAddress {
18 fn from(value: Ipv4Address) -> Self {
19 IpAddress::V4(value)
20 }
21}
22
23impl From<Ipv6Address> for IpAddress {
24 fn from(value: Ipv6Address) -> Self {
25 IpAddress::V6(value)
26 }
27}
28
29impl fmt::Display for IpAddress {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 IpAddress::V4(addr) => write!(f, "{addr}"),
33 IpAddress::V6(addr) => write!(f, "{addr}"),
34 }
35 }
36}
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
40pub enum Network {
41 V4(Ipv4Network),
42 V6(Ipv6Network),
43}
44
45impl From<Ipv4Network> for Network {
46 fn from(value: Ipv4Network) -> Self {
47 Network::V4(value)
48 }
49}
50
51impl From<Ipv6Network> for Network {
52 fn from(value: Ipv6Network) -> Self {
53 Network::V6(value)
54 }
55}
56
57impl fmt::Display for Network {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 match self {
60 Network::V4(net) => write!(f, "{net}"),
61 Network::V6(net) => write!(f, "{net}"),
62 }
63 }
64}