about summary refs log tree commit diff
path: root/src/libstd/net
diff options
context:
space:
mode:
authorSean McArthur <sean.monstar@gmail.com>2017-01-28 12:53:17 -0800
committerSean McArthur <sean.monstar@gmail.com>2017-01-28 13:02:48 -0800
commit87dcbcada247560d9ce5df28dd76034182e5b492 (patch)
treedf676dd1371ce540a0950a223d9d4bf6ab2ad4c8 /src/libstd/net
parentc81c1d6a41babf7e34120625727211cad7b40b87 (diff)
downloadrust-87dcbcada247560d9ce5df28dd76034182e5b492.tar.gz
rust-87dcbcada247560d9ce5df28dd76034182e5b492.zip
add From<[u8; n]> impls for IpAddr
Diffstat (limited to 'src/libstd/net')
-rw-r--r--src/libstd/net/ip.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs
index 7803cf728f2..cfd06dfcdd5 100644
--- a/src/libstd/net/ip.rs
+++ b/src/libstd/net/ip.rs
@@ -656,6 +656,13 @@ impl From<[u8; 4]> for Ipv4Addr {
     }
 }
 
+#[stable(feature = "ip_from_slice", since = "1.17.0")]
+impl From<[u8; 4]> for IpAddr {
+    fn from(octets: [u8; 4]) -> IpAddr {
+        IpAddr::V4(Ipv4Addr::from(octets))
+    }
+}
+
 impl Ipv6Addr {
     /// Creates a new IPv6 address from eight 16-bit segments.
     ///
@@ -1166,6 +1173,21 @@ impl From<[u16; 8]> for Ipv6Addr {
     }
 }
 
+
+#[stable(feature = "ip_from_slice", since = "1.17.0")]
+impl From<[u8; 16]> for IpAddr {
+    fn from(octets: [u8; 16]) -> IpAddr {
+        IpAddr::V6(Ipv6Addr::from(octets))
+    }
+}
+
+#[stable(feature = "ip_from_slice", since = "1.17.0")]
+impl From<[u16; 8]> for IpAddr {
+    fn from(octets: [u16; 8]) -> IpAddr {
+        IpAddr::V6(Ipv6Addr::from(octets))
+    }
+}
+
 // Tests for this module
 #[cfg(all(test, not(target_os = "emscripten")))]
 mod tests {