File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -34,3 +34,40 @@ impl IpAddress {
3434 Self ( ip_addr)
3535 }
3636}
37+
38+ impl From < core:: net:: Ipv4Addr > for IpAddress {
39+ fn from ( t : core:: net:: Ipv4Addr ) -> Self {
40+ Self :: new_v4 ( t. octets ( ) )
41+ }
42+ }
43+
44+ impl From < IpAddress > for core:: net:: Ipv4Addr {
45+ fn from ( IpAddress ( o) : IpAddress ) -> Self {
46+ Self :: from ( [ o[ 0 ] , o[ 1 ] , o[ 2 ] , o[ 3 ] ] )
47+ }
48+ }
49+
50+ impl From < core:: net:: Ipv6Addr > for IpAddress {
51+ fn from ( t : core:: net:: Ipv6Addr ) -> Self {
52+ Self :: new_v6 ( t. octets ( ) )
53+ }
54+ }
55+
56+ impl From < IpAddress > for core:: net:: Ipv6Addr {
57+ fn from ( value : IpAddress ) -> Self {
58+ Self :: from ( value. 0 )
59+ }
60+ }
61+
62+ impl From < core:: net:: IpAddr > for IpAddress {
63+ fn from ( t : core:: net:: IpAddr ) -> Self {
64+ match t {
65+ core:: net:: IpAddr :: V4 ( a) => a. into ( ) ,
66+ core:: net:: IpAddr :: V6 ( a) => a. into ( ) ,
67+ }
68+ }
69+ }
70+
71+ // NOTE: We cannot impl From<IpAddress> for core::net::IpAddr
72+ // because IpAddress is a raw union, with nothing indicating
73+ // whether it should be considered v4 or v6.
You can’t perform that action at this time.
0 commit comments