about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Nelson <jnelson@cloudflare.com>2022-05-27 09:39:54 -0500
committerJoshua Nelson <jnelson@cloudflare.com>2022-06-21 23:03:58 -0500
commitcf483a130cdfa1e72678fd98c74b11fedb3ae8dd (patch)
tree928f20752862e496670022b2387f7e0d518c4a87
parented1e3512dc5e0b25c693b95f39281c97c7bd3819 (diff)
downloadrust-cf483a130cdfa1e72678fd98c74b11fedb3ae8dd.tar.gz
rust-cf483a130cdfa1e72678fd98c74b11fedb3ae8dd.zip
`impl<T: AsFd> AsFd for {Arc,Box}<T>`
-rw-r--r--library/std/src/os/fd/owned.rs31
-rw-r--r--library/std/src/os/fd/raw.rs5
2 files changed, 33 insertions, 3 deletions
diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs
index dd965ddc01e..d661a13edc5 100644
--- a/library/std/src/os/fd/owned.rs
+++ b/library/std/src/os/fd/owned.rs
@@ -355,3 +355,34 @@ impl From<OwnedFd> for crate::net::UdpSocket {
         ))))
     }
 }
+
+#[stable(feature = "io_safety", since = "1.63.0")]
+/// This impl allows implementing traits that require `AsFd` on Arc.
+/// ```
+/// # #[cfg(any(unix, target_os = "wasi"))] mod group_cfg {
+/// # #[cfg(target_os = "wasi")]
+/// # use std::os::wasi::io::AsFd;
+/// # #[cfg(unix)]
+/// # use std::os::unix::io::AsFd;
+/// use std::net::UdpSocket;
+/// use std::sync::Arc;
+///
+/// trait MyTrait: AsFd {}
+/// impl MyTrait for Arc<UdpSocket> {}
+/// impl MyTrait for Box<UdpSocket> {}
+/// # }
+/// ```
+impl<T: AsFd> AsFd for crate::sync::Arc<T> {
+    #[inline]
+    fn as_fd(&self) -> BorrowedFd<'_> {
+        (**self).as_fd()
+    }
+}
+
+#[stable(feature = "io_safety", since = "1.63.0")]
+impl<T: AsFd> AsFd for Box<T> {
+    #[inline]
+    fn as_fd(&self) -> BorrowedFd<'_> {
+        (**self).as_fd()
+    }
+}
diff --git a/library/std/src/os/fd/raw.rs b/library/std/src/os/fd/raw.rs
index 7b6d2402aa9..345beb1824d 100644
--- a/library/std/src/os/fd/raw.rs
+++ b/library/std/src/os/fd/raw.rs
@@ -223,8 +223,7 @@ impl<'a> AsRawFd for io::StderrLock<'a> {
     }
 }
 
-#[stable(feature = "asraw_ptrs", since = "1.63.0")]
-/// This blanket impl allows implementing custom traits that require `AsRawFd` on Arc.
+/// This impl allows implementing traits that require `AsRawFd` on Arc.
 /// ```
 /// # #[cfg(any(unix, target_os = "wasi"))] mod group_cfg {
 /// # #[cfg(target_os = "wasi")]
@@ -247,7 +246,7 @@ impl<T: AsRawFd> AsRawFd for crate::sync::Arc<T> {
     }
 }
 
-#[stable(feature = "asraw_ptrs", since = "1.63.0")]
+#[stable(feature = "asrawfd_ptrs", since = "1.63.0")]
 impl<T: AsRawFd> AsRawFd for Box<T> {
     #[inline]
     fn as_raw_fd(&self) -> RawFd {