Skip to content

Commit

Permalink
fs: impl AsRawFd / AsRawHandle for File (#1827)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carllerche committed Nov 27, 2019
1 parent ebf5f37 commit c146f48
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tokio/src/fs/file.rs
Expand Up @@ -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()
}
}
14 changes: 14 additions & 0 deletions tokio/tests/support/mock_file.rs
Expand Up @@ -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!();
}
}

0 comments on commit c146f48

Please sign in to comment.