]> git.lizzy.rs Git - rust.git/commitdiff
add From<[u8; n]> impls for IpAddr
authorSean McArthur <sean.monstar@gmail.com>
Sat, 28 Jan 2017 20:53:17 +0000 (12:53 -0800)
committerSean McArthur <sean.monstar@gmail.com>
Sat, 28 Jan 2017 21:02:48 +0000 (13:02 -0800)
src/libstd/net/ip.rs

index 7803cf728f2e98777855e0fa32e7f09e4985769b..cfd06dfcdd51b0b5e18811bedb860bf6d00f9e90 100644 (file)
@@ -656,6 +656,13 @@ fn from(ip: u32) -> 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 @@ fn from_inner(addr: c::in6_addr) -> 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 {