about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorTomoaki Kawada <kawada@kmckk.co.jp>2023-08-23 16:19:58 +0900
committerTomoaki Kawada <kawada@kmckk.co.jp>2023-11-08 10:48:49 +0900
commitcf9c4a32f3293dc3acd2149248880d15d922c7a6 (patch)
tree11bac824d38d0debd867456577e5f11702775645 /library/std/src
parentddfe168e6c6e6c3f8fe8c35568c84cbe11506cb9 (diff)
downloadrust-cf9c4a32f3293dc3acd2149248880d15d922c7a6.tar.gz
rust-cf9c4a32f3293dc3acd2149248880d15d922c7a6.zip
kmc-solid: Implement `AsFd` and conversion to/from `OwnedFd` for `{TcpStream,TcpListener,UdpSocket}`
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/os/solid/io.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/library/std/src/os/solid/io.rs b/library/std/src/os/solid/io.rs
index 6bddfc779fb..67fc94830d0 100644
--- a/library/std/src/os/solid/io.rs
+++ b/library/std/src/os/solid/io.rs
@@ -245,6 +245,32 @@ impl AsFd for OwnedFd {
     }
 }
 
+macro_rules! impl_owned_fd_traits {
+    ($($t:ident)*) => {$(
+        impl AsFd for net::$t {
+            #[inline]
+            fn as_fd(&self) -> BorrowedFd<'_> {
+                unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
+            }
+        }
+
+        impl From<net::$t> for OwnedFd {
+            #[inline]
+            fn from(socket: net::$t) -> OwnedFd {
+                unsafe { Self::from_raw_fd(socket.into_raw_fd()) }
+            }
+        }
+
+        impl From<OwnedFd> for net::$t {
+            #[inline]
+            fn from(owned_fd: OwnedFd) -> Self {
+                unsafe { Self::from_raw_fd(owned_fd.into_raw_fd()) }
+            }
+        }
+    )*};
+}
+impl_owned_fd_traits! { TcpStream TcpListener UdpSocket }
+
 /// A trait to extract the raw SOLID Sockets file descriptor from an underlying
 /// object.
 pub trait AsRawFd {