summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolai Vazquez <hello@nikolaivazquez.com>2020-08-28 03:53:51 -0400
committerGitHub <noreply@github.com>2020-08-28 09:53:51 +0200
commit827077409c8a8ef7adb4d05d522fcf6c1949c876 (patch)
tree3d843322074068d69c66c1df9d564c8b0d439f33
parentd600ab9a8f37e9eff3fa8587069a816b65b6da0b (diff)
fs: implement FromRawFd & FromRawHandle for File (#2792)
-rw-r--r--tokio/src/fs/file.rs14
-rw-r--r--tokio/tests/support/mock_file.rs14
2 files changed, 28 insertions, 0 deletions
diff --git a/tokio/src/fs/file.rs b/tokio/src/fs/file.rs
index 2c36806d..b801ba99 100644
--- a/tokio/src/fs/file.rs
+++ b/tokio/src/fs/file.rs
@@ -778,9 +778,23 @@ impl std::os::unix::io::AsRawFd for File {
}
}
+#[cfg(unix)]
+impl std::os::unix::io::FromRawFd for File {
+ unsafe fn from_raw_fd(fd: std::os::unix::io::RawFd) -> Self {
+ sys::File::from_raw_fd(fd).into()
+ }
+}
+
#[cfg(windows)]
impl std::os::windows::io::AsRawHandle for File {
fn as_raw_handle(&self) -> std::os::windows::io::RawHandle {
self.std.as_raw_handle()
}
}
+
+#[cfg(windows)]
+impl std::os::windows::io::FromRawHandle for File {
+ unsafe fn from_raw_handle(handle: std::os::windows::io::RawHandle) -> Self {
+ sys::File::from_raw_handle(handle).into()
+ }
+}
diff --git a/tokio/tests/support/mock_file.rs b/tokio/tests/support/mock_file.rs
index 9895f835..1ce326b6 100644
--- a/tokio/tests/support/mock_file.rs
+++ b/tokio/tests/support/mock_file.rs
@@ -273,9 +273,23 @@ impl std::os::unix::io::AsRawFd for File {
}
}
+#[cfg(unix)]
+impl std::os::unix::io::FromRawFd for File {
+ unsafe fn from_raw_fd(_: std::os::unix::io::RawFd) -> Self {
+ unimplemented!();
+ }
+}
+
#[cfg(windows)]
impl std::os::windows::io::AsRawHandle for File {
fn as_raw_handle(&self) -> std::os::windows::io::RawHandle {
unimplemented!();
}
}
+
+#[cfg(windows)]
+impl std::os::windows::io::FromRawHandle for File {
+ unsafe fn from_raw_handle(_: std::os::windows::io::RawHandle) -> Self {
+ unimplemented!();
+ }
+}