added Eq and TotalEq instances for IpAddr
This commit is contained in:
parent
7e022c590f
commit
47443753f1
1 changed files with 21 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue