• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Implementations of io-lifetimes' traits for fs_err's types. In the
2 //! future, we'll prefer to have crates provide their own impls; this is
3 //! just a temporary measure.
4 
5 #[cfg(any(unix, target_os = "wasi"))]
6 use crate::{AsFd, BorrowedFd, IntoFd, OwnedFd};
7 #[cfg(windows)]
8 use crate::{AsHandle, BorrowedHandle, IntoHandle, OwnedHandle};
9 #[cfg(unix)]
10 use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd};
11 #[cfg(target_os = "wasi")]
12 use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd};
13 #[cfg(windows)]
14 use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle};
15 
16 #[cfg(any(unix, target_os = "wasi"))]
17 impl AsFd for fs_err::File {
18     #[inline]
as_fd(&self) -> BorrowedFd<'_>19     fn as_fd(&self) -> BorrowedFd<'_> {
20         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
21     }
22 }
23 
24 #[cfg(windows)]
25 impl AsHandle for fs_err::File {
26     #[inline]
as_handle(&self) -> BorrowedHandle<'_>27     fn as_handle(&self) -> BorrowedHandle<'_> {
28         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
29     }
30 }
31 
32 #[cfg(any(unix, target_os = "wasi"))]
33 impl IntoFd for fs_err::File {
34     #[inline]
into_fd(self) -> OwnedFd35     fn into_fd(self) -> OwnedFd {
36         unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
37     }
38 }
39 
40 #[cfg(any(unix, target_os = "wasi"))]
41 impl From<fs_err::File> for OwnedFd {
42     #[inline]
from(owned: fs_err::File) -> Self43     fn from(owned: fs_err::File) -> Self {
44         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
45     }
46 }
47 
48 #[cfg(windows)]
49 impl IntoHandle for fs_err::File {
50     #[inline]
into_handle(self) -> OwnedHandle51     fn into_handle(self) -> OwnedHandle {
52         unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) }
53     }
54 }
55 
56 #[cfg(windows)]
57 impl From<fs_err::File> for OwnedHandle {
58     #[inline]
from(owned: fs_err::File) -> Self59     fn from(owned: fs_err::File) -> Self {
60         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
61     }
62 }
63