Skip to content

Commit

Permalink
fs: implement FromRawFd & FromRawHandle for File (#2792)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvzqz committed Aug 28, 2020
1 parent d600ab9 commit 8270774
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 @@ -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()
}
}
14 changes: 14 additions & 0 deletions tokio/tests/support/mock_file.rs
Expand Up @@ -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!();
}
}

0 comments on commit 8270774

Please sign in to comment.