diff options
| author | Dan Gohman <dev@sunfishcode.online> | 2021-08-21 19:42:30 -0700 |
|---|---|---|
| committer | Dan Gohman <dev@sunfishcode.online> | 2021-08-21 19:42:30 -0700 |
| commit | be483ff4c10e8bea2a4bac4849063ad5686a737b (patch) | |
| tree | eaeffe1c607056c22b66920048302842d834e879 | |
| parent | 99b73e81b351d036449e76ad753160853625c5b6 (diff) | |
Implement `AsFd` etc. for `UnixListener`.
Implement `AsFd`, `From<OwnedFd>`, and `Into<OwnedFd>` for `UnixListener`. This is a follow-up to #87329.
| -rw-r--r-- | library/std/src/os/unix/net/listener.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/library/std/src/os/unix/net/listener.rs b/library/std/src/os/unix/net/listener.rs index 9066c71794f..4508367b9ee 100644 --- a/library/std/src/os/unix/net/listener.rs +++ b/library/std/src/os/unix/net/listener.rs @@ -1,5 +1,5 @@ use super::{sockaddr_un, SocketAddr, UnixStream}; -use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; +use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; use crate::path::Path; use crate::sys::cvt; use crate::sys::net::Socket; @@ -262,6 +262,30 @@ impl IntoRawFd for UnixListener { } } +#[unstable(feature = "io_safety", issue = "87074")] +impl AsFd for UnixListener { + #[inline] + fn as_fd(&self) -> BorrowedFd<'_> { + self.0.as_inner().as_fd() + } +} + +#[unstable(feature = "io_safety", issue = "87074")] +impl From<OwnedFd> for UnixListener { + #[inline] + fn from(fd: OwnedFd) -> UnixListener { + UnixListener(Socket::from_inner(FromInner::from_inner(OwnedFd::from(fd)))) + } +} + +#[unstable(feature = "io_safety", issue = "87074")] +impl From<UnixListener> for OwnedFd { + #[inline] + fn from(listener: UnixListener) -> OwnedFd { + listener.0.into_inner().into_inner().into() + } +} + #[stable(feature = "unix_socket", since = "1.10.0")] impl<'a> IntoIterator for &'a UnixListener { type Item = io::Result<UnixStream>; |
