net: improve discoverability of TcpSocket (#3471)

This commit is contained in:
Alice Ryhl 2021-01-28 14:09:14 +01:00 committed by GitHub
parent 4968f59af6
commit cd7526873c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -8,8 +8,6 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV
/// # DNS /// # DNS
/// ///
/// Implementations of `ToSocketAddrs` for string types require a DNS lookup. /// Implementations of `ToSocketAddrs` for string types require a DNS lookup.
/// These implementations are only provided when Tokio is used with the
/// **`net`** feature flag.
/// ///
/// # Calling /// # Calling
/// ///

View File

@ -64,9 +64,6 @@ impl TcpListener {
/// method. /// method.
/// ///
/// The address type can be any implementor of the [`ToSocketAddrs`] trait. /// The address type can be any implementor of the [`ToSocketAddrs`] trait.
/// Note that strings only implement this trait when the **`net`** feature
/// is enabled, as strings may contain domain names that need to be resolved.
///
/// If `addr` yields multiple addresses, bind will be attempted with each of /// If `addr` yields multiple addresses, bind will be attempted with each of
/// the addresses until one succeeds and returns the listener. If none of /// the addresses until one succeeds and returns the listener. If none of
/// the addresses succeed in creating a listener, the error returned from /// the addresses succeed in creating a listener, the error returned from
@ -74,7 +71,11 @@ impl TcpListener {
/// ///
/// This function sets the `SO_REUSEADDR` option on the socket. /// This function sets the `SO_REUSEADDR` option on the socket.
/// ///
/// To configure the socket before binding, you can use the [`TcpSocket`]
/// type.
///
/// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs /// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs
/// [`TcpSocket`]: struct@crate::net::TcpSocket
/// ///
/// # Examples /// # Examples
/// ///

View File

@ -25,7 +25,8 @@ cfg_net! {
/// A TCP stream between a local and a remote socket. /// A TCP stream between a local and a remote socket.
/// ///
/// A TCP stream can either be created by connecting to an endpoint, via the /// A TCP stream can either be created by connecting to an endpoint, via the
/// [`connect`] method, or by [accepting] a connection from a [listener]. /// [`connect`] method, or by [accepting] a connection from a [listener]. A
/// TCP stream can also be created via the [`TcpSocket`] type.
/// ///
/// Reading and writing to a `TcpStream` is usually done using the /// Reading and writing to a `TcpStream` is usually done using the
/// convenience methods found on the [`AsyncReadExt`] and [`AsyncWriteExt`] /// convenience methods found on the [`AsyncReadExt`] and [`AsyncWriteExt`]
@ -34,6 +35,7 @@ cfg_net! {
/// [`connect`]: method@TcpStream::connect /// [`connect`]: method@TcpStream::connect
/// [accepting]: method@crate::net::TcpListener::accept /// [accepting]: method@crate::net::TcpListener::accept
/// [listener]: struct@crate::net::TcpListener /// [listener]: struct@crate::net::TcpListener
/// [`TcpSocket`]: struct@crate::net::TcpSocket
/// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt /// [`AsyncReadExt`]: trait@crate::io::AsyncReadExt
/// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt /// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
/// ///
@ -76,16 +78,17 @@ impl TcpStream {
/// Opens a TCP connection to a remote host. /// Opens a TCP connection to a remote host.
/// ///
/// `addr` is an address of the remote host. Anything which implements the /// `addr` is an address of the remote host. Anything which implements the
/// [`ToSocketAddrs`] trait can be supplied as the address. Note that /// [`ToSocketAddrs`] trait can be supplied as the address. If `addr`
/// strings only implement this trait when the **`net`** feature is enabled, /// yields multiple addresses, connect will be attempted with each of the
/// as strings may contain domain names that need to be resolved. /// addresses until a connection is successful. If none of the addresses
/// result in a successful connection, the error returned from the last
/// connection attempt (the last address) is returned.
/// ///
/// If `addr` yields multiple addresses, connect will be attempted with each /// To configure the socket before connecting, you can use the [`TcpSocket`]
/// of the addresses until a connection is successful. If none of the /// type.
/// addresses result in a successful connection, the error returned from the
/// last connection attempt (the last address) is returned.
/// ///
/// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs /// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs
/// [`TcpSocket`]: struct@crate::net::TcpSocket
/// ///
/// # Examples /// # Examples
/// ///