diff options
author | Carl Lerche <me@carllerche.com> | 2019-11-26 16:00:26 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-26 16:00:26 -0800 |
commit | c146f48f0b4f1fbecb1bed3d5a32222506d50704 (patch) | |
tree | faea0baa1839c87666f19d9d6f1c064515172e64 | |
parent | ebf5f37989fd8cc901a771afbe73fecc7b216325 (diff) |
fs: impl AsRawFd / AsRawHandle for File (#1827)
This provides the ability to get the raw OS handle for a `File`. The
`Into*` variant cannot be provided as `File` needs to maintain ownership
of the `File`. The actual handle may have been moved to a background
thread.
-rw-r--r-- | tokio/src/fs/file.rs | 14 | ||||
-rw-r--r-- | tokio/tests/support/mock_file.rs | 14 |
2 files changed, 28 insertions, 0 deletions
diff --git a/tokio/src/fs/file.rs b/tokio/src/fs/file.rs index af7be586..c4558272 100644 --- a/tokio/src/fs/file.rs +++ b/tokio/src/fs/file.rs @@ -600,3 +600,17 @@ impl fmt::Debug for File { .finish() } } + +#[cfg(unix)] +impl std::os::unix::io::AsRawFd for File { + fn as_raw_fd(&self) -> std::os::unix::io::RawFd { + self.std.as_raw_fd() + } +} + +#[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() + } +} diff --git a/tokio/tests/support/mock_file.rs b/tokio/tests/support/mock_file.rs index 7f3beee8..44aa7b3f 100644 --- a/tokio/tests/support/mock_file.rs +++ b/tokio/tests/support/mock_file.rs @@ -263,3 +263,17 @@ impl fmt::Debug for File { fmt.debug_struct("mock::File").finish() } } + +#[cfg(unix)] +impl std::os::unix::io::AsRawFd for File { + fn as_raw_fd(&self) -> std::os::unix::io::RawFd { + unimplemented!(); + } +} + +#[cfg(windows)] +impl std::os::windows::io::AsRawHandle for File { + fn as_raw_handle(&self) -> std::os::windows::io::RawHandle { + unimplemented!(); + } +} |