1//! Implementations of io-lifetimes' traits for os_pipe'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, FromFd, IntoFd, OwnedFd}; 7#[cfg(windows)] 8use crate::{AsHandle, BorrowedHandle, FromHandle, 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 os_pipe::PipeReader { 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 os_pipe::PipeReader { 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 os_pipe::PipeReader { 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<os_pipe::PipeReader> for OwnedFd { 42 #[inline] 43 fn from(owned: os_pipe::PipeReader) -> Self { 44 unsafe { Self::from_raw_fd(owned.into_raw_fd()) } 45 } 46} 47 48#[cfg(windows)] 49impl IntoHandle for os_pipe::PipeReader { 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<os_pipe::PipeReader> for OwnedHandle { 58 #[inline] 59 fn from(owned: os_pipe::PipeReader) -> Self { 60 unsafe { Self::from_raw_handle(owned.into_raw_handle()) } 61 } 62} 63 64#[cfg(any(unix, target_os = "wasi"))] 65impl FromFd for os_pipe::PipeReader { 66 #[inline] 67 fn from_fd(owned: OwnedFd) -> Self { 68 unsafe { Self::from_raw_fd(owned.into_raw_fd()) } 69 } 70} 71 72#[cfg(any(unix, target_os = "wasi"))] 73impl From<OwnedFd> for os_pipe::PipeReader { 74 #[inline] 75 fn from(owned: OwnedFd) -> Self { 76 unsafe { Self::from_raw_fd(owned.into_raw_fd()) } 77 } 78} 79 80#[cfg(windows)] 81impl FromHandle for os_pipe::PipeReader { 82 #[inline] 83 fn from_handle(owned: OwnedHandle) -> Self { 84 unsafe { Self::from_raw_handle(owned.into_raw_handle()) } 85 } 86} 87 88#[cfg(windows)] 89impl From<OwnedHandle> for os_pipe::PipeReader { 90 #[inline] 91 fn from(owned: OwnedHandle) -> Self { 92 unsafe { Self::from_raw_handle(owned.into_raw_handle()) } 93 } 94} 95 96#[cfg(any(unix, target_os = "wasi"))] 97impl AsFd for os_pipe::PipeWriter { 98 #[inline] 99 fn as_fd(&self) -> BorrowedFd<'_> { 100 unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) } 101 } 102} 103 104#[cfg(windows)] 105impl AsHandle for os_pipe::PipeWriter { 106 #[inline] 107 fn as_handle(&self) -> BorrowedHandle<'_> { 108 unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) } 109 } 110} 111 112#[cfg(any(unix, target_os = "wasi"))] 113impl IntoFd for os_pipe::PipeWriter { 114 #[inline] 115 fn into_fd(self) -> OwnedFd { 116 unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) } 117 } 118} 119 120#[cfg(any(unix, target_os = "wasi"))] 121impl From<os_pipe::PipeWriter> for OwnedFd { 122 #[inline] 123 fn from(owned: os_pipe::PipeWriter) -> Self { 124 unsafe { Self::from_raw_fd(owned.into_raw_fd()) } 125 } 126} 127 128#[cfg(windows)] 129impl IntoHandle for os_pipe::PipeWriter { 130 #[inline] 131 fn into_handle(self) -> OwnedHandle { 132 unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) } 133 } 134} 135 136#[cfg(windows)] 137impl From<os_pipe::PipeWriter> for OwnedHandle { 138 #[inline] 139 fn from(owned: os_pipe::PipeWriter) -> Self { 140 unsafe { Self::from_raw_handle(owned.into_raw_handle()) } 141 } 142} 143 144#[cfg(any(unix, target_os = "wasi"))] 145impl FromFd for os_pipe::PipeWriter { 146 #[inline] 147 fn from_fd(owned: OwnedFd) -> Self { 148 unsafe { Self::from_raw_fd(owned.into_raw_fd()) } 149 } 150} 151 152#[cfg(any(unix, target_os = "wasi"))] 153impl From<OwnedFd> for os_pipe::PipeWriter { 154 #[inline] 155 fn from(owned: OwnedFd) -> Self { 156 unsafe { Self::from_raw_fd(owned.into_raw_fd()) } 157 } 158} 159 160#[cfg(windows)] 161impl FromHandle for os_pipe::PipeWriter { 162 #[inline] 163 fn from_handle(owned: OwnedHandle) -> Self { 164 unsafe { Self::from_raw_handle(owned.into_raw_handle()) } 165 } 166} 167 168#[cfg(windows)] 169impl From<OwnedHandle> for os_pipe::PipeWriter { 170 #[inline] 171 fn from(owned: OwnedHandle) -> Self { 172 unsafe { Self::from_raw_handle(owned.into_raw_handle()) } 173 } 174} 175