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"))] 6use crate::{AsFd, BorrowedFd, IntoFd, OwnedFd}; 7#[cfg(windows)] 8use crate::{AsHandle, BorrowedHandle, IntoHandle, OwnedHandle}; 9#[cfg(unix)] 10use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd}; 11#[cfg(target_os = "wasi")] 12use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd}; 13#[cfg(windows)] 14use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle}; 15 16#[cfg(any(unix, target_os = "wasi"))] 17impl AsFd for fs_err::File { 18 #[inline] 19 fn as_fd(&self) -> BorrowedFd<'_> { 20 unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } 21 } 22} 23 24#[cfg(windows)] 25impl AsHandle for fs_err::File { 26 #[inline] 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"))] 33impl IntoFd for fs_err::File { 34 #[inline] 35 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"))] 41impl From<fs_err::File> for OwnedFd { 42 #[inline] 43 fn from(owned: fs_err::File) -> Self { 44 unsafe { Self::from_raw_fd(owned.into_raw_fd()) } 45 } 46} 47 48#[cfg(windows)] 49impl IntoHandle for fs_err::File { 50 #[inline] 51 fn into_handle(self) -> OwnedHandle { 52 unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } 53 } 54} 55 56#[cfg(windows)] 57impl From<fs_err::File> for OwnedHandle { 58 #[inline] 59 fn from(owned: fs_err::File) -> Self { 60 unsafe { Self::from_raw_handle(owned.into_raw_handle()) } 61 } 62} 63