about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTom Lee <github@tomlee.co>2014-02-10 02:21:50 -0800
committerTom Lee <github@tomlee.co>2014-02-10 02:21:50 -0800
commite205185095a642c38d8f252d1fe499204d5ef971 (patch)
treecea7d9c9bd71e58d0ec023fd1eebcfafe98f90aa
parentb66ec3483bd5081bcc829efb88ceb841189b754d (diff)
downloadrust-e205185095a642c38d8f252d1fe499204d5ef971.tar.gz
rust-e205185095a642c38d8f252d1fe499204d5ef971.zip
IterBytes for IpAddr and SocketAddr
-rw-r--r--src/libstd/io/net/ip.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs
index 4fb631eb3d6..f042661117e 100644
--- a/src/libstd/io/net/ip.rs
+++ b/src/libstd/io/net/ip.rs
@@ -14,11 +14,12 @@ use iter::Iterator;
 use option::{Option, None, Some};
 use str::StrSlice;
 use to_str::ToStr;
+use to_bytes::IterBytes;
 use vec::{MutableCloneableVector, ImmutableVector, MutableVector};
 
 pub type Port = u16;
 
-#[deriving(Eq, TotalEq, Clone)]
+#[deriving(Eq, TotalEq, Clone, IterBytes)]
 pub enum IpAddr {
     Ipv4Addr(u8, u8, u8, u8),
     Ipv6Addr(u16, u16, u16, u16, u16, u16, u16, u16)
@@ -48,7 +49,7 @@ impl ToStr for IpAddr {
     }
 }
 
-#[deriving(Eq, TotalEq, Clone)]
+#[deriving(Eq, TotalEq, Clone, IterBytes)]
 pub struct SocketAddr {
     ip: IpAddr,
     port: Port,
@@ -339,6 +340,7 @@ impl FromStr for SocketAddr {
 mod test {
     use prelude::*;
     use super::*;
+    use to_bytes::ToBytes;
 
     #[test]
     fn test_from_str_ipv4() {
@@ -441,4 +443,13 @@ mod test {
         assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_str(), ~"8:9:a:b:c:d:e:f");
     }
 
+    #[test]
+    fn ipv4_addr_to_bytes() {
+        Ipv4Addr(123, 20, 12, 56).to_bytes(true);
+    }
+
+    #[test]
+    fn socket_addr_to_bytes() {
+        SocketAddr { ip: Ipv4Addr(1, 2, 3, 4), port: 1234 }.to_bytes(true);
+    }
 }