Skip to content

Commit df5830a

Browse files
committed
Added links throughout std::net::ToSocketAddrs' documentation
Part of #29363 In the section about the default implementations of ToSocketAddrs, I moved the bulletpoint of SocketAddrV4 & SocketAddrV6 to the one stating that SocketAddr is constructed trivially, as this is what's actually the case
1 parent 0df7398 commit df5830a

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

src/libstd/net/addr.rs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -559,37 +559,51 @@ impl hash::Hash for SocketAddrV6 {
559559
}
560560

561561
/// A trait for objects which can be converted or resolved to one or more
562-
/// `SocketAddr` values.
562+
/// [`SocketAddr`] values.
563563
///
564564
/// This trait is used for generic address resolution when constructing network
565565
/// objects. By default it is implemented for the following types:
566566
///
567-
/// * `SocketAddr`, `SocketAddrV4`, `SocketAddrV6` - `to_socket_addrs` is
568-
/// identity function.
567+
/// * [`SocketAddr`]: [`to_socket_addrs`] is the identity function.
569568
///
570-
/// * `(IpvNAddr, u16)` - `to_socket_addrs` constructs `SocketAddr` trivially.
569+
/// * [`SocketAddrV4`], [`SocketAddrV6`], `(`[`IpAddr`]`, `[`u16`]`)`,
570+
/// `(`[`Ipv4Addr`]`, `[`u16`]`)`, `(`[`Ipv6Addr`]`, `[`u16`]`)`:
571+
/// [`to_socket_addrs`] constructs a [`SocketAddr`] trivially.
571572
///
572-
/// * `(&str, u16)` - the string should be either a string representation of an
573-
/// IP address expected by `FromStr` implementation for `IpvNAddr` or a host
573+
/// * `(`[`&str`]`, `[`u16`]`)`: the string should be either a string representation
574+
/// of an [`IpAddr`] address as expected by [`FromStr`] implementation or a host
574575
/// name.
575576
///
576-
/// * `&str` - the string should be either a string representation of a
577-
/// `SocketAddr` as expected by its `FromStr` implementation or a string like
578-
/// `<host_name>:<port>` pair where `<port>` is a `u16` value.
577+
/// * [`&str`]: the string should be either a string representation of a
578+
/// [`SocketAddr`] as expected by its [`FromStr`] implementation or a string like
579+
/// `<host_name>:<port>` pair where `<port>` is a [`u16`] value.
579580
///
580-
/// This trait allows constructing network objects like `TcpStream` or
581-
/// `UdpSocket` easily with values of various types for the bind/connection
581+
/// This trait allows constructing network objects like [`TcpStream`] or
582+
/// [`UdpSocket`] easily with values of various types for the bind/connection
582583
/// address. It is needed because sometimes one type is more appropriate than
583584
/// the other: for simple uses a string like `"localhost:12345"` is much nicer
584-
/// than manual construction of the corresponding `SocketAddr`, but sometimes
585-
/// `SocketAddr` value is *the* main source of the address, and converting it to
585+
/// than manual construction of the corresponding [`SocketAddr`], but sometimes
586+
/// [`SocketAddr`] value is *the* main source of the address, and converting it to
586587
/// some other type (e.g. a string) just for it to be converted back to
587-
/// `SocketAddr` in constructor methods is pointless.
588+
/// [`SocketAddr`] in constructor methods is pointless.
588589
///
589590
/// Addresses returned by the operating system that are not IP addresses are
590591
/// silently ignored.
591592
///
592-
/// Some examples:
593+
/// [`FromStr`]: ../../std/str/trait.FromStr.html
594+
/// [`IpAddr`]: ../../std/net/enum.IpAddr.html
595+
/// [`Ipv4Addr`]: ../../std/net/struct.Ipv4Addr.html
596+
/// [`Ipv6Addr`]: ../../std/net/struct.Ipv6Addr.html
597+
/// [`SocketAddr`]: ../../std/net/enum.SocketAddr.html
598+
/// [`SocketAddrV4`]: ../../std/net/struct.SocketAddrV4.html
599+
/// [`SocketAddrV6`]: ../../std/net/struct.SocketAddrV6.html
600+
/// [`&str`]: ../../std/primitive.str.html
601+
/// [`TcpStream`]: ../../std/net/struct.TcpStream.html
602+
/// [`to_socket_addrs`]: #tymethod.to_socket_addrs
603+
/// [`UdpSocket`]: ../../std/net/struct.UdpSocket.html
604+
/// [`u16`]: ../../std/primitive.u16.html
605+
///
606+
/// # Examples
593607
///
594608
/// ```no_run
595609
/// use std::net::{SocketAddrV4, TcpStream, UdpSocket, TcpListener, Ipv4Addr};
@@ -622,17 +636,21 @@ pub trait ToSocketAddrs {
622636
#[stable(feature = "rust1", since = "1.0.0")]
623637
type Iter: Iterator<Item=SocketAddr>;
624638

625-
/// Converts this object to an iterator of resolved `SocketAddr`s.
639+
/// Converts this object to an iterator of resolved [`SocketAddr`]s.
626640
///
627641
/// The returned iterator may not actually yield any values depending on the
628642
/// outcome of any resolution performed.
629643
///
630644
/// Note that this function may block the current thread while resolution is
631645
/// performed.
632646
///
647+
/// [`SocketAddr`]: ../../std/net/enum.SocketAddr.html
648+
///
633649
/// # Errors
634650
///
635-
/// Any errors encountered during resolution will be returned as an `Err`.
651+
/// Any errors encountered during resolution will be returned as an [`Err`].
652+
///
653+
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
636654
#[stable(feature = "rust1", since = "1.0.0")]
637655
fn to_socket_addrs(&self) -> io::Result<Self::Iter>;
638656
}

0 commit comments

Comments
 (0)