added Eq and TotalEq instances for IpAddr

This commit is contained in:
Eric Reed 2013-06-17 12:33:46 -07:00
parent 7e022c590f
commit 47443753f1

View file

@ -8,7 +8,28 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::cmp::{Eq, TotalEq, eq};
pub enum IpAddr {
Ipv4(u8, u8, u8, u8, u16),
Ipv6
}
impl Eq for IpAddr {
fn eq(&self, other: &IpAddr) -> bool {
match (*self, *other) {
(Ipv4(a,b,c,d,e), Ipv4(f,g,h,i,j)) => a == f && b == g && c == h && d == i && e == j,
(Ipv6, Ipv6) => fail!(),
_ => false
}
}
fn ne(&self, other: &IpAddr) -> bool {
!eq(self, other)
}
}
impl TotalEq for IpAddr {
fn equals(&self, other: &IpAddr) -> bool {
*self == *other
}
}