diff options
| author | Eric Reed <ereed@mozilla.com> | 2013-06-17 12:33:46 -0700 |
|---|---|---|
| committer | Eric Reed <ereed@mozilla.com> | 2013-06-17 12:33:46 -0700 |
| commit | 47443753f1197877f51f4a66d3475f8c9e4d5bc2 (patch) | |
| tree | 79fb14e4ac5e7cae242df46c526ac60bd17ab01e /src/libstd/rt/io | |
| parent | 7e022c590fb0fb6083be7825df90045505e6fe47 (diff) | |
added Eq and TotalEq instances for IpAddr
Diffstat (limited to 'src/libstd/rt/io')
| -rw-r--r-- | src/libstd/rt/io/net/ip.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libstd/rt/io/net/ip.rs b/src/libstd/rt/io/net/ip.rs index df1dfe4d38a..f885c7f2788 100644 --- a/src/libstd/rt/io/net/ip.rs +++ b/src/libstd/rt/io/net/ip.rs @@ -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 + } +} |
