Repository: tokio-rs/tokio
File: tokio/src/net/unix/socket.rs (Rust)

Code before:
    /// ```no_run
    /// use tokio::net::UnixSocket;
    /// use std::error::Error;
    ///
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn Error>> {
    ///     let dir = tempfile::tempdir().unwrap();
    ///     let path = dir.path().join("bind_path");
    ///     let socket = UnixSocket::new_stream()?;
    ///     socket.bind(path)?;
    ///
    ///     let listener = socket.listen(1024)?;
    ///
    ///     Ok(())
    /// }
    /// ```
    ///
    /// Setting socket options not explicitly provided by `UnixSocket` may be done by
    /// accessing the `RawFd`/`RawSocket` using [`AsRawFd`]/[`AsRawSocket`] and
    /// setting the option with a crate like [`socket2`].
    ///
    /// [`RawFd`]: https://doc.rust-lang.org/std/os/unix/io/type.RawFd.html
    /// [`RawSocket`]: https://doc.rust-lang.org/std/os/windows/io/type.RawSocket.html
    /// [`AsRawFd`]: https://doc.rust-lang.org/std/os/unix/io/trait.AsRawFd.html
    /// [`AsRawSocket`]: https://doc.rust-lang.org/std/os/windows/io/trait.AsRawSocket.html
    /// [`socket2`]: https://docs.rs/socket2/
    #[derive(Debug)]
    pub struct UnixSocket {
        inner: socket2::Socket,
    }
}

impl UnixSocket {
    fn ty(&self) -> socket2::Type {
        self.inner.r#type().unwrap()
    }

    /// Creates a new Unix datagram socket.
    ///
    /// Calls `socket(2)` with `AF_UNIX` and `SOCK_DGRAM`.
    ///
    /// # Returns
    ///
    /// On success, the newly created `UnixSocket` is returned. If an error is
    /// encountered, it is returned instead.
    pub fn new_datagram() -> io::Result<UnixSocket> {
        UnixSocket::new(socket2::Type::DGRAM)
    }

    /// Creates a new Unix stream socket.
    ///

Review comment (suggestion):
Please don't use links unless that's the only way to get it to work. For example:
```
[`RawFd`]: std::os::unix::io::RawFd
```

Code after:
    /// ```no_run
    /// use tokio::net::UnixSocket;
    /// use std::error::Error;
    ///
    /// #[tokio::main]
    /// async fn main() -> Result<(), Box<dyn Error>> {
    ///     let dir = tempfile::tempdir().unwrap();
    ///     let path = dir.path().join("bind_path");
    ///     let socket = UnixSocket::new_stream()?;
    ///     socket.bind(path)?;
    ///
    ///     let listener = socket.listen(1024)?;
    ///
    ///     Ok(())
    /// }
    /// ```
    ///
    /// Setting socket options not explicitly provided by `UnixSocket` may be done by
    /// accessing the [`RawFd`]/[`RawSocket`] using [`AsRawFd`]/[`AsRawSocket`] and
    /// setting the option with a crate like [`socket2`].
    ///
    /// [`RawFd`]: std::os::fd::RawFd
    /// [`RawSocket`]: https://doc.rust-lang.org/std/os/windows/io/type.RawSocket.html
    /// [`AsRawFd`]: std::os::fd::AsRawFd
    /// [`AsRawSocket`]: https://doc.rust-lang.org/std/os/windows/io/trait.AsRawSocket.html
    /// [`socket2`]: https://docs.rs/socket2/
    #[derive(Debug)]
    pub struct UnixSocket {
        inner: socket2::Socket,
    }
}

impl UnixSocket {
    fn ty(&self) -> socket2::Type {
        self.inner.r#type().unwrap()
    }

    /// Creates a new Unix datagram socket.
    ///
    /// Calls `socket(2)` with `AF_UNIX` and `SOCK_DGRAM`.
    ///
    /// # Returns
    ///
    /// On success, the newly created [`UnixSocket`] is returned. If an error is
    /// encountered, it is returned instead.
    pub fn new_datagram() -> io::Result<UnixSocket> {
        UnixSocket::new(socket2::Type::DGRAM)
    }

    /// Creates a new Unix stream socket.
    ///