Repository: tokio-rs/tokio
File: tokio/src/net/tcp/stream.rs (Rust)

Code before:
    ///     // Connect to a peer
    ///     let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
    ///
    ///     // Write some data.
    ///     stream.write_all(b"hello world!").await?;
    ///
    ///     Ok(())
    /// }
    /// ```
    ///
    /// The [`write_all`] method is defined on the [`AsyncWriteExt`] trait.
    ///
    /// [`write_all`]: fn@crate::io::AsyncWriteExt::write_all
    /// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
    ///
    /// To shut down the stream in the write direction, you can call the
    /// [`shutdown()`] method. This will cause the other peer to receive a read of
    /// length 0, indicating that no more data will be sent. This only closes
    /// the stream in one direction.
    ///
    /// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown
    pub struct TcpStream {
        io: PollEvented<mio::net::TcpStream>,
    }

    impl AsRef<TcpStream> for TcpStream {
        fn as_ref(&self) -> &Self {
            self
        }
    }
}

impl TcpStream {
    cfg_not_wasi! {
        /// Opens a TCP connection to a remote host.
        ///
        /// `addr` is an address of the remote host. Anything which implements the
        /// [`ToSocketAddrs`] trait can be supplied as the address.  If `addr`
        /// yields multiple addresses, connect will be attempted with each of the
        /// 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.
        ///
        /// To configure the socket before connecting, you can use the [`TcpSocket`]
        /// type.
        ///
        /// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs
        /// [`TcpSocket`]: struct@crate::net::TcpSocket
        ///
        /// # Examples
        ///

Review comment (bug):
Please move this outside of the `cfg_net!` block. I think a good location is next to the `Debug` impl.

https://github.com/tokio-rs/tokio/blob/4a9c83e91f6700cb631ef9fa04c9643eabd22d92/tokio/src/net/tcp/stream.rs#L1465-L1469

Code after:
    ///     // Connect to a peer
    ///     let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
    ///
    ///     // Write some data.
    ///     stream.write_all(b"hello world!").await?;
    ///
    ///     Ok(())
    /// }
    /// ```
    ///
    /// The [`write_all`] method is defined on the [`AsyncWriteExt`] trait.
    ///
    /// [`write_all`]: fn@crate::io::AsyncWriteExt::write_all
    /// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt
    ///
    /// To shut down the stream in the write direction, you can call the
    /// [`shutdown()`] method. This will cause the other peer to receive a read of
    /// length 0, indicating that no more data will be sent. This only closes
    /// the stream in one direction.
    ///
    /// [`shutdown()`]: fn@crate::io::AsyncWriteExt::shutdown
    pub struct TcpStream {
        io: PollEvented<mio::net::TcpStream>,
    }
}

impl TcpStream {
    cfg_not_wasi! {
        /// Opens a TCP connection to a remote host.
        ///
        /// `addr` is an address of the remote host. Anything which implements the
        /// [`ToSocketAddrs`] trait can be supplied as the address.  If `addr`
        /// yields multiple addresses, connect will be attempted with each of the
        /// 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.
        ///
        /// To configure the socket before connecting, you can use the [`TcpSocket`]
        /// type.
        ///
        /// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs
        /// [`TcpSocket`]: struct@crate::net::TcpSocket
        ///
        /// # Examples
        ///
        /// ```no_run
        /// use tokio::net::TcpStream;
        /// use tokio::io::AsyncWriteExt;
        /// use std::error::Error;
        ///
        /// #[tokio::main]