From 2d365c6b7ae0ed76d85e6dccaccc5782728e5d0b Mon Sep 17 00:00:00 2001 From: Yamakaky Date: Mon, 12 Dec 2016 15:34:09 -0500 Subject: [PATCH] Impl From for IpAddr and SocketAddr. Fixes https://github.com/rust-lang/rfcs/issues/1816. --- src/libstd/net/addr.rs | 14 ++++++++++++++ src/libstd/net/ip.rs | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index 1ce37f6cc0a..f5348934310 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -446,6 +446,20 @@ fn from_inner(addr: c::sockaddr_in6) -> SocketAddrV6 { } } +#[stable(feature = "ip_from_ip", since = "1.16.0")] +impl From for SocketAddr { + fn from(sock4: SocketAddrV4) -> SocketAddr { + SocketAddr::V4(sock4) + } +} + +#[stable(feature = "ip_from_ip", since = "1.16.0")] +impl From for SocketAddr { + fn from(sock6: SocketAddrV6) -> SocketAddr { + SocketAddr::V6(sock6) + } +} + impl<'a> IntoInner<(*const c::sockaddr, c::socklen_t)> for &'a SocketAddr { fn into_inner(self) -> (*const c::sockaddr, c::socklen_t) { match *self { diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index 36a1aed8400..249f1c76680 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -524,12 +524,14 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { } } +#[stable(feature = "ip_from_ip", since = "1.16.0")] impl From for IpAddr { fn from(ipv4: Ipv4Addr) -> IpAddr { IpAddr::V4(ipv4) } } +#[stable(feature = "ip_from_ip", since = "1.16.0")] impl From for IpAddr { fn from(ipv6: Ipv6Addr) -> IpAddr { IpAddr::V6(ipv6)