Skip to content

Commit 2d365c6

Browse files
committed
Impl From<inner> for IpAddr and SocketAddr.
Fixes rust-lang/rfcs#1816.
1 parent 40053a4 commit 2d365c6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/libstd/net/addr.rs

+14
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,20 @@ impl FromInner<c::sockaddr_in6> for SocketAddrV6 {
446446
}
447447
}
448448

449+
#[stable(feature = "ip_from_ip", since = "1.16.0")]
450+
impl From<SocketAddrV4> for SocketAddr {
451+
fn from(sock4: SocketAddrV4) -> SocketAddr {
452+
SocketAddr::V4(sock4)
453+
}
454+
}
455+
456+
#[stable(feature = "ip_from_ip", since = "1.16.0")]
457+
impl From<SocketAddrV6> for SocketAddr {
458+
fn from(sock6: SocketAddrV6) -> SocketAddr {
459+
SocketAddr::V6(sock6)
460+
}
461+
}
462+
449463
impl<'a> IntoInner<(*const c::sockaddr, c::socklen_t)> for &'a SocketAddr {
450464
fn into_inner(self) -> (*const c::sockaddr, c::socklen_t) {
451465
match *self {

src/libstd/net/ip.rs

+2
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,14 @@ impl fmt::Display for IpAddr {
524524
}
525525
}
526526

527+
#[stable(feature = "ip_from_ip", since = "1.16.0")]
527528
impl From<Ipv4Addr> for IpAddr {
528529
fn from(ipv4: Ipv4Addr) -> IpAddr {
529530
IpAddr::V4(ipv4)
530531
}
531532
}
532533

534+
#[stable(feature = "ip_from_ip", since = "1.16.0")]
533535
impl From<Ipv6Addr> for IpAddr {
534536
fn from(ipv6: Ipv6Addr) -> IpAddr {
535537
IpAddr::V6(ipv6)

0 commit comments

Comments
 (0)