• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"))]
6 use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd};
7 #[cfg(windows)]
8 use crate::{AsHandle, BorrowedHandle, FromHandle, 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 os_pipe::PipeReader {
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 os_pipe::PipeReader {
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 os_pipe::PipeReader {
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<os_pipe::PipeReader> for OwnedFd {
42     #[inline]
from(owned: os_pipe::PipeReader) -> Self43     fn from(owned: os_pipe::PipeReader) -> Self {
44         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
45     }
46 }
47 
48 #[cfg(windows)]
49 impl IntoHandle for os_pipe::PipeReader {
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<os_pipe::PipeReader> for OwnedHandle {
58     #[inline]
from(owned: os_pipe::PipeReader) -> Self59     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"))]
65 impl FromFd for os_pipe::PipeReader {
66     #[inline]
from_fd(owned: OwnedFd) -> Self67     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"))]
73 impl From<OwnedFd> for os_pipe::PipeReader {
74     #[inline]
from(owned: OwnedFd) -> Self75     fn from(owned: OwnedFd) -> Self {
76         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
77     }
78 }
79 
80 #[cfg(windows)]
81 impl FromHandle for os_pipe::PipeReader {
82     #[inline]
from_handle(owned: OwnedHandle) -> Self83     fn from_handle(owned: OwnedHandle) -> Self {
84         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
85     }
86 }
87 
88 #[cfg(windows)]
89 impl From<OwnedHandle> for os_pipe::PipeReader {
90     #[inline]
from(owned: OwnedHandle) -> Self91     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"))]
97 impl AsFd for os_pipe::PipeWriter {
98     #[inline]
as_fd(&self) -> BorrowedFd<'_>99     fn as_fd(&self) -> BorrowedFd<'_> {
100         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
101     }
102 }
103 
104 #[cfg(windows)]
105 impl AsHandle for os_pipe::PipeWriter {
106     #[inline]
as_handle(&self) -> BorrowedHandle<'_>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"))]
113 impl IntoFd for os_pipe::PipeWriter {
114     #[inline]
into_fd(self) -> OwnedFd115     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"))]
121 impl From<os_pipe::PipeWriter> for OwnedFd {
122     #[inline]
from(owned: os_pipe::PipeWriter) -> Self123     fn from(owned: os_pipe::PipeWriter) -> Self {
124         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
125     }
126 }
127 
128 #[cfg(windows)]
129 impl IntoHandle for os_pipe::PipeWriter {
130     #[inline]
into_handle(self) -> OwnedHandle131     fn into_handle(self) -> OwnedHandle {
132         unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) }
133     }
134 }
135 
136 #[cfg(windows)]
137 impl From<os_pipe::PipeWriter> for OwnedHandle {
138     #[inline]
from(owned: os_pipe::PipeWriter) -> Self139     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"))]
145 impl FromFd for os_pipe::PipeWriter {
146     #[inline]
from_fd(owned: OwnedFd) -> Self147     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"))]
153 impl From<OwnedFd> for os_pipe::PipeWriter {
154     #[inline]
from(owned: OwnedFd) -> Self155     fn from(owned: OwnedFd) -> Self {
156         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
157     }
158 }
159 
160 #[cfg(windows)]
161 impl FromHandle for os_pipe::PipeWriter {
162     #[inline]
from_handle(owned: OwnedHandle) -> Self163     fn from_handle(owned: OwnedHandle) -> Self {
164         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
165     }
166 }
167 
168 #[cfg(windows)]
169 impl From<OwnedHandle> for os_pipe::PipeWriter {
170     #[inline]
from(owned: OwnedHandle) -> Self171     fn from(owned: OwnedHandle) -> Self {
172         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
173     }
174 }
175