From 40053a46ff3b5d7a516d1f91e89cd928cf253347 Mon Sep 17 00:00:00 2001 From: Yamakaky Date: Mon, 12 Dec 2016 15:34:09 -0500 Subject: [PATCH] Impl From for IpAddr. Fixes https://github.com/rust-lang/rfcs/issues/1816. --- src/libstd/net/ip.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index 6aab7486004..36a1aed8400 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -524,6 +524,18 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { } } +impl From for IpAddr { + fn from(ipv4: Ipv4Addr) -> IpAddr { + IpAddr::V4(ipv4) + } +} + +impl From for IpAddr { + fn from(ipv6: Ipv6Addr) -> IpAddr { + IpAddr::V6(ipv6) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Display for Ipv4Addr { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {