Impl From<inner> for IpAddr and SocketAddr.

Fixes https://github.com/rust-lang/rfcs/issues/1816.
This commit is contained in:
Yamakaky 2016-12-12 15:34:09 -05:00
parent 40053a46ff
commit 2d365c6b7a
No known key found for this signature in database
GPG Key ID: 1F5120C66C0B64F7
2 changed files with 16 additions and 0 deletions

View File

@ -446,6 +446,20 @@ fn from_inner(addr: c::sockaddr_in6) -> SocketAddrV6 {
}
}
#[stable(feature = "ip_from_ip", since = "1.16.0")]
impl From<SocketAddrV4> for SocketAddr {
fn from(sock4: SocketAddrV4) -> SocketAddr {
SocketAddr::V4(sock4)
}
}
#[stable(feature = "ip_from_ip", since = "1.16.0")]
impl From<SocketAddrV6> 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 {

View File

@ -524,12 +524,14 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
}
}
#[stable(feature = "ip_from_ip", since = "1.16.0")]
impl From<Ipv4Addr> for IpAddr {
fn from(ipv4: Ipv4Addr) -> IpAddr {
IpAddr::V4(ipv4)
}
}
#[stable(feature = "ip_from_ip", since = "1.16.0")]
impl From<Ipv6Addr> for IpAddr {
fn from(ipv6: Ipv6Addr) -> IpAddr {
IpAddr::V6(ipv6)