Skip to content

Commit 4744375

Browse files
author
Eric Reed
committed
added Eq and TotalEq instances for IpAddr
1 parent 7e022c5 commit 4744375

File tree

1 file changed

+21
-0
lines changed
  • src/libstd/rt/io/net

1 file changed

+21
-0
lines changed

src/libstd/rt/io/net/ip.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,28 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::cmp::{Eq, TotalEq, eq};
12+
1113
pub enum IpAddr {
1214
Ipv4(u8, u8, u8, u8, u16),
1315
Ipv6
1416
}
17+
18+
impl Eq for IpAddr {
19+
fn eq(&self, other: &IpAddr) -> bool {
20+
match (*self, *other) {
21+
(Ipv4(a,b,c,d,e), Ipv4(f,g,h,i,j)) => a == f && b == g && c == h && d == i && e == j,
22+
(Ipv6, Ipv6) => fail!(),
23+
_ => false
24+
}
25+
}
26+
fn ne(&self, other: &IpAddr) -> bool {
27+
!eq(self, other)
28+
}
29+
}
30+
31+
impl TotalEq for IpAddr {
32+
fn equals(&self, other: &IpAddr) -> bool {
33+
*self == *other
34+
}
35+
}

0 commit comments

Comments
 (0)