Skip to content

Commit 3cdebfb

Browse files
Rollup merge of rust-lang#53522 - phungleson:fix-impl-from-for-addr, 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.
2 parents b80cb47 + 4ced4f3 commit 3cdebfb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/libstd/net/addr.rs

+8
Original file line numberDiff line numberDiff line change
@@ -554,20 +554,28 @@ impl FromInner<c::sockaddr_in6> for SocketAddrV6 {
554554

555555
#[stable(feature = "ip_from_ip", since = "1.16.0")]
556556
impl From<SocketAddrV4> for SocketAddr {
557+
/// Converts a [`SocketAddrV4`] into a [`SocketAddr::V4`].
557558
fn from(sock4: SocketAddrV4) -> SocketAddr {
558559
SocketAddr::V4(sock4)
559560
}
560561
}
561562

562563
#[stable(feature = "ip_from_ip", since = "1.16.0")]
563564
impl From<SocketAddrV6> for SocketAddr {
565+
/// Converts a [`SocketAddrV6`] into a [`SocketAddr::V6`].
564566
fn from(sock6: SocketAddrV6) -> SocketAddr {
565567
SocketAddr::V6(sock6)
566568
}
567569
}
568570

569571
#[stable(feature = "addr_from_into_ip", since = "1.17.0")]
570572
impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr {
573+
/// Converts a tuple struct (Into<[`IpAddr`]>, `u16`) into a [`SocketAddr`].
574+
///
575+
/// This conversion creates a [`SocketAddr::V4`] for a [`IpAddr::V4`]
576+
/// and creates a [`SocketAddr::V6`] for a [`IpAddr::V6`].
577+
///
578+
/// `u16` is treated as port of the newly created [`SocketAddr`].
571579
fn from(pieces: (I, u16)) -> SocketAddr {
572580
SocketAddr::new(pieces.0.into(), pieces.1)
573581
}

0 commit comments

Comments
 (0)