Repository: tokio-rs/tokio
File: tokio/src/io/async_fd.rs (Rust)

Code before:
    /// This function panics if there is no current reactor set, or if the `rt`
    /// feature flag is not enabled.
    #[inline]
    #[track_caller]
    pub fn with_interest(inner: T, interest: Interest) -> io::Result<Self>
    where
        T: AsRawFd,
    {
        Self::new_with_handle_and_interest(inner, scheduler::Handle::current(), interest)
    }

    #[track_caller]
    pub(crate) fn new_with_handle_and_interest(
        inner: T,
        handle: scheduler::Handle,
        interest: Interest,
    ) -> io::Result<Self> {
        Self::try_new_with_handle_and_interest(inner, handle, interest).map_err(Into::into)
    }

    /// Creates an [`AsyncFd`] backed by (and taking ownership of) an object
    /// implementing [`AsRawFd`]. The backing file descriptor is cached at the
    /// time of creation.
    ///
    /// Only configures the [`Interest::READABLE`] and [`Interest::WRITABLE`] interests. For more
    /// control, use [`AsyncFd::with_interest`].
    ///
    /// This method must be called in the context of a tokio runtime.
    ///
    /// In the case of failure, it returns [`AsyncFdTryNewError`] that contains the original object
    /// passed to this function.
    ///
    /// # Panics
    ///
    /// This function panics if there is no current reactor set, or if the `rt`
    /// feature flag is not enabled.
    #[inline]
    #[track_caller]
    pub fn try_new(inner: T) -> Result<Self, AsyncFdTryNewError<T>>
    where
        T: AsRawFd,
    {
        Self::try_with_interest(inner, Interest::READABLE | Interest::WRITABLE)
    }

    /// Creates an [`AsyncFd`] backed by (and taking ownership of) an object
    /// implementing [`AsRawFd`], with a specific [`Interest`]. The backing
    /// file descriptor is cached at the time of creation.
    ///
    /// In the case of failure, it returns [`AsyncFdTryNewError`] that contains the original object
    /// passed to this function.

Review comment (suggestion):
I think this should be

```suggestion
    /// Only configures the [`Interest::READABLE`] and [`Interest::WRITABLE`] interests. For more
    /// control, use [`AsyncFd::try_with_interest`].
```

Code after:
    /// This function panics if there is no current reactor set, or if the `rt`
    /// feature flag is not enabled.
    #[inline]
    #[track_caller]
    pub fn with_interest(inner: T, interest: Interest) -> io::Result<Self>
    where
        T: AsRawFd,
    {
        Self::new_with_handle_and_interest(inner, scheduler::Handle::current(), interest)
    }

    #[track_caller]
    pub(crate) fn new_with_handle_and_interest(
        inner: T,
        handle: scheduler::Handle,
        interest: Interest,
    ) -> io::Result<Self> {
        Self::try_new_with_handle_and_interest(inner, handle, interest).map_err(Into::into)
    }

    /// Creates an [`AsyncFd`] backed by (and taking ownership of) an object
    /// implementing [`AsRawFd`]. The backing file descriptor is cached at the
    /// time of creation.
    ///
    /// Only configures the [`Interest::READABLE`] and [`Interest::WRITABLE`] interests. For more
    /// control, use [`AsyncFd::try_with_interest`].
    ///
    /// This method must be called in the context of a tokio runtime.
    ///
    /// In the case of failure, it returns [`AsyncFdTryNewError`] that contains the original object
    /// passed to this function.
    ///
    /// # Panics
    ///
    /// This function panics if there is no current reactor set, or if the `rt`
    /// feature flag is not enabled.
    #[inline]
    #[track_caller]
    pub fn try_new(inner: T) -> Result<Self, AsyncFdTryNewError<T>>
    where
        T: AsRawFd,
    {
        Self::try_with_interest(inner, Interest::READABLE | Interest::WRITABLE)
    }

    /// Creates an [`AsyncFd`] backed by (and taking ownership of) an object
    /// implementing [`AsRawFd`], with a specific [`Interest`]. The backing
    /// file descriptor is cached at the time of creation.
    ///
    /// In the case of failure, it returns [`AsyncFdTryNewError`] that contains the original object
    /// passed to this function.