Skip to content

Commit

Permalink
Rollup merge of rust-lang#53522 - phungleson:fix-impl-from-for-addr, …
Browse files Browse the repository at this point in the history
…r=TimNN

Add doc for impl From for Addr

As part of issue rust-lang#51430 (cc @skade).

The impl is very simple, let me know if we need to go into any details.

Additionally, I added `#[inline]` for the conversion method, let me know if it is un-necessary or might break something.
  • Loading branch information
GuillaumeGomez authored Sep 18, 2018
2 parents b80cb47 + 4ced4f3 commit 3cdebfb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libstd/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,20 +554,28 @@ impl FromInner<c::sockaddr_in6> for SocketAddrV6 {

#[stable(feature = "ip_from_ip", since = "1.16.0")]
impl From<SocketAddrV4> for SocketAddr {
/// Converts a [`SocketAddrV4`] into a [`SocketAddr::V4`].
fn from(sock4: SocketAddrV4) -> SocketAddr {
SocketAddr::V4(sock4)
}
}

#[stable(feature = "ip_from_ip", since = "1.16.0")]
impl From<SocketAddrV6> for SocketAddr {
/// Converts a [`SocketAddrV6`] into a [`SocketAddr::V6`].
fn from(sock6: SocketAddrV6) -> SocketAddr {
SocketAddr::V6(sock6)
}
}

#[stable(feature = "addr_from_into_ip", since = "1.17.0")]
impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr {
/// Converts a tuple struct (Into<[`IpAddr`]>, `u16`) into a [`SocketAddr`].
///
/// This conversion creates a [`SocketAddr::V4`] for a [`IpAddr::V4`]
/// and creates a [`SocketAddr::V6`] for a [`IpAddr::V6`].
///
/// `u16` is treated as port of the newly created [`SocketAddr`].
fn from(pieces: (I, u16)) -> SocketAddr {
SocketAddr::new(pieces.0.into(), pieces.1)
}
Expand Down

0 comments on commit 3cdebfb

Please sign in to comment.