• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![allow(deprecated)] // Don't warn on `IntoFd` and `FromFd` impls.
2 
3 #[cfg(any(unix, target_os = "wasi"))]
4 use crate::{AsFd, FromFd, IntoFd};
5 #[cfg(windows)]
6 use crate::{AsHandle, AsSocket, FromHandle, FromSocket, IntoHandle, IntoSocket};
7 #[cfg(any(unix, target_os = "wasi"))]
8 use crate::{BorrowedFd, OwnedFd};
9 #[cfg(windows)]
10 use crate::{BorrowedHandle, BorrowedSocket, HandleOrInvalid, OwnedHandle, OwnedSocket};
11 #[cfg(unix)]
12 use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd};
13 #[cfg(target_os = "wasi")]
14 use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd};
15 #[cfg(windows)]
16 use std::os::windows::io::{
17     AsRawHandle, AsRawSocket, FromRawHandle, FromRawSocket, IntoRawHandle, IntoRawSocket,
18 };
19 
20 #[cfg(any(unix, target_os = "wasi"))]
21 impl AsFd for BorrowedFd<'_> {
22     #[inline]
as_fd(&self) -> BorrowedFd<'_>23     fn as_fd(&self) -> BorrowedFd<'_> {
24         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
25     }
26 }
27 
28 #[cfg(windows)]
29 impl AsHandle for BorrowedHandle<'_> {
30     #[inline]
as_handle(&self) -> BorrowedHandle<'_>31     fn as_handle(&self) -> BorrowedHandle<'_> {
32         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
33     }
34 }
35 
36 #[cfg(windows)]
37 impl AsSocket for BorrowedSocket<'_> {
38     #[inline]
as_socket(&self) -> BorrowedSocket<'_>39     fn as_socket(&self) -> BorrowedSocket<'_> {
40         unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
41     }
42 }
43 
44 #[cfg(any(unix, target_os = "wasi"))]
45 impl AsFd for OwnedFd {
46     #[inline]
as_fd(&self) -> BorrowedFd<'_>47     fn as_fd(&self) -> BorrowedFd<'_> {
48         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
49     }
50 }
51 
52 #[cfg(windows)]
53 impl AsHandle for OwnedHandle {
54     #[inline]
as_handle(&self) -> BorrowedHandle<'_>55     fn as_handle(&self) -> BorrowedHandle<'_> {
56         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
57     }
58 }
59 
60 #[cfg(windows)]
61 impl AsSocket for OwnedSocket {
62     #[inline]
as_socket(&self) -> BorrowedSocket<'_>63     fn as_socket(&self) -> BorrowedSocket<'_> {
64         unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
65     }
66 }
67 
68 #[cfg(any(unix, target_os = "wasi"))]
69 impl IntoFd for OwnedFd {
70     #[inline]
into_fd(self) -> OwnedFd71     fn into_fd(self) -> OwnedFd {
72         unsafe { Self::from_raw_fd(self.into_raw_fd()) }
73     }
74 }
75 
76 #[cfg(windows)]
77 impl IntoHandle for OwnedHandle {
78     #[inline]
into_handle(self) -> OwnedHandle79     fn into_handle(self) -> OwnedHandle {
80         unsafe { Self::from_raw_handle(self.into_raw_handle()) }
81     }
82 }
83 
84 #[cfg(windows)]
85 impl IntoSocket for OwnedSocket {
86     #[inline]
into_socket(self) -> OwnedSocket87     fn into_socket(self) -> OwnedSocket {
88         unsafe { Self::from_raw_socket(self.into_raw_socket()) }
89     }
90 }
91 
92 #[cfg(any(unix, target_os = "wasi"))]
93 impl FromFd for OwnedFd {
94     #[inline]
from_fd(owned: OwnedFd) -> Self95     fn from_fd(owned: OwnedFd) -> Self {
96         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
97     }
98 }
99 
100 #[cfg(windows)]
101 impl FromHandle for OwnedHandle {
102     #[inline]
from_handle(owned: OwnedHandle) -> Self103     fn from_handle(owned: OwnedHandle) -> Self {
104         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
105     }
106 }
107 
108 #[cfg(windows)]
109 impl FromSocket for OwnedSocket {
110     #[inline]
from_socket(owned: OwnedSocket) -> Self111     fn from_socket(owned: OwnedSocket) -> Self {
112         unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
113     }
114 }
115 
116 #[cfg(windows)]
117 impl FromHandle for HandleOrInvalid {
118     #[inline]
from_handle(owned: OwnedHandle) -> Self119     fn from_handle(owned: OwnedHandle) -> Self {
120         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
121     }
122 }
123 
124 #[cfg(windows)]
125 impl From<OwnedHandle> for HandleOrInvalid {
126     #[inline]
from(owned: OwnedHandle) -> Self127     fn from(owned: OwnedHandle) -> Self {
128         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
129     }
130 }
131 
132 #[cfg(any(unix, target_os = "wasi"))]
133 impl AsFd for std::fs::File {
134     #[inline]
as_fd(&self) -> BorrowedFd<'_>135     fn as_fd(&self) -> BorrowedFd<'_> {
136         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
137     }
138 }
139 
140 #[cfg(windows)]
141 impl AsHandle for std::fs::File {
142     #[inline]
as_handle(&self) -> BorrowedHandle<'_>143     fn as_handle(&self) -> BorrowedHandle<'_> {
144         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
145     }
146 }
147 
148 #[cfg(any(unix, target_os = "wasi"))]
149 impl IntoFd for std::fs::File {
150     #[inline]
into_fd(self) -> OwnedFd151     fn into_fd(self) -> OwnedFd {
152         unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
153     }
154 }
155 
156 #[cfg(any(unix, target_os = "wasi"))]
157 impl From<std::fs::File> for OwnedFd {
158     #[inline]
from(owned: std::fs::File) -> Self159     fn from(owned: std::fs::File) -> Self {
160         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
161     }
162 }
163 
164 #[cfg(windows)]
165 impl IntoHandle for std::fs::File {
166     #[inline]
into_handle(self) -> OwnedHandle167     fn into_handle(self) -> OwnedHandle {
168         unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) }
169     }
170 }
171 
172 #[cfg(windows)]
173 impl From<std::fs::File> for OwnedHandle {
174     #[inline]
from(owned: std::fs::File) -> Self175     fn from(owned: std::fs::File) -> Self {
176         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
177     }
178 }
179 
180 #[cfg(any(unix, target_os = "wasi"))]
181 impl FromFd for std::fs::File {
182     #[inline]
from_fd(owned: OwnedFd) -> Self183     fn from_fd(owned: OwnedFd) -> Self {
184         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
185     }
186 }
187 
188 #[cfg(any(unix, target_os = "wasi"))]
189 impl From<OwnedFd> for std::fs::File {
190     #[inline]
from(owned: OwnedFd) -> Self191     fn from(owned: OwnedFd) -> Self {
192         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
193     }
194 }
195 
196 #[cfg(windows)]
197 impl FromHandle for std::fs::File {
198     #[inline]
from_handle(owned: OwnedHandle) -> Self199     fn from_handle(owned: OwnedHandle) -> Self {
200         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
201     }
202 }
203 
204 #[cfg(windows)]
205 impl From<OwnedHandle> for std::fs::File {
206     #[inline]
from(owned: OwnedHandle) -> Self207     fn from(owned: OwnedHandle) -> Self {
208         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
209     }
210 }
211 
212 #[cfg(any(unix, target_os = "wasi"))]
213 impl AsFd for std::net::TcpStream {
214     #[inline]
as_fd(&self) -> BorrowedFd<'_>215     fn as_fd(&self) -> BorrowedFd<'_> {
216         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
217     }
218 }
219 
220 #[cfg(windows)]
221 impl AsSocket for std::net::TcpStream {
222     #[inline]
as_socket(&self) -> BorrowedSocket<'_>223     fn as_socket(&self) -> BorrowedSocket<'_> {
224         unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
225     }
226 }
227 
228 #[cfg(any(unix, target_os = "wasi"))]
229 impl IntoFd for std::net::TcpStream {
230     #[inline]
into_fd(self) -> OwnedFd231     fn into_fd(self) -> OwnedFd {
232         unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
233     }
234 }
235 
236 #[cfg(any(unix, target_os = "wasi"))]
237 impl From<std::net::TcpStream> for OwnedFd {
238     #[inline]
from(owned: std::net::TcpStream) -> Self239     fn from(owned: std::net::TcpStream) -> Self {
240         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
241     }
242 }
243 
244 #[cfg(windows)]
245 impl IntoSocket for std::net::TcpStream {
246     #[inline]
into_socket(self) -> OwnedSocket247     fn into_socket(self) -> OwnedSocket {
248         unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) }
249     }
250 }
251 
252 #[cfg(windows)]
253 impl From<std::net::TcpStream> for OwnedSocket {
254     #[inline]
from(owned: std::net::TcpStream) -> Self255     fn from(owned: std::net::TcpStream) -> Self {
256         unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
257     }
258 }
259 
260 #[cfg(any(unix, target_os = "wasi"))]
261 impl FromFd for std::net::TcpStream {
262     #[inline]
from_fd(owned: OwnedFd) -> Self263     fn from_fd(owned: OwnedFd) -> Self {
264         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
265     }
266 }
267 
268 #[cfg(any(unix, target_os = "wasi"))]
269 impl From<OwnedFd> for std::net::TcpStream {
270     #[inline]
from(owned: OwnedFd) -> Self271     fn from(owned: OwnedFd) -> Self {
272         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
273     }
274 }
275 
276 #[cfg(windows)]
277 impl FromSocket for std::net::TcpStream {
278     #[inline]
from_socket(owned: OwnedSocket) -> Self279     fn from_socket(owned: OwnedSocket) -> Self {
280         unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
281     }
282 }
283 
284 #[cfg(windows)]
285 impl From<OwnedSocket> for std::net::TcpStream {
286     #[inline]
from(owned: OwnedSocket) -> Self287     fn from(owned: OwnedSocket) -> Self {
288         unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
289     }
290 }
291 
292 #[cfg(any(unix, target_os = "wasi"))]
293 impl AsFd for std::net::TcpListener {
294     #[inline]
as_fd(&self) -> BorrowedFd<'_>295     fn as_fd(&self) -> BorrowedFd<'_> {
296         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
297     }
298 }
299 
300 #[cfg(windows)]
301 impl AsSocket for std::net::TcpListener {
302     #[inline]
as_socket(&self) -> BorrowedSocket<'_>303     fn as_socket(&self) -> BorrowedSocket<'_> {
304         unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
305     }
306 }
307 
308 #[cfg(any(unix, target_os = "wasi"))]
309 impl IntoFd for std::net::TcpListener {
310     #[inline]
into_fd(self) -> OwnedFd311     fn into_fd(self) -> OwnedFd {
312         unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
313     }
314 }
315 
316 #[cfg(any(unix, target_os = "wasi"))]
317 impl From<std::net::TcpListener> for OwnedFd {
318     #[inline]
from(owned: std::net::TcpListener) -> Self319     fn from(owned: std::net::TcpListener) -> Self {
320         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
321     }
322 }
323 
324 #[cfg(windows)]
325 impl IntoSocket for std::net::TcpListener {
326     #[inline]
into_socket(self) -> OwnedSocket327     fn into_socket(self) -> OwnedSocket {
328         unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) }
329     }
330 }
331 
332 #[cfg(windows)]
333 impl From<std::net::TcpListener> for OwnedSocket {
334     #[inline]
from(owned: std::net::TcpListener) -> Self335     fn from(owned: std::net::TcpListener) -> Self {
336         unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
337     }
338 }
339 
340 #[cfg(any(unix, target_os = "wasi"))]
341 impl FromFd for std::net::TcpListener {
342     #[inline]
from_fd(owned: OwnedFd) -> Self343     fn from_fd(owned: OwnedFd) -> Self {
344         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
345     }
346 }
347 
348 #[cfg(any(unix, target_os = "wasi"))]
349 impl From<OwnedFd> for std::net::TcpListener {
350     #[inline]
from(owned: OwnedFd) -> Self351     fn from(owned: OwnedFd) -> Self {
352         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
353     }
354 }
355 
356 #[cfg(windows)]
357 impl FromSocket for std::net::TcpListener {
358     #[inline]
from_socket(owned: OwnedSocket) -> Self359     fn from_socket(owned: OwnedSocket) -> Self {
360         unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
361     }
362 }
363 
364 #[cfg(windows)]
365 impl From<OwnedSocket> for std::net::TcpListener {
366     #[inline]
from(owned: OwnedSocket) -> Self367     fn from(owned: OwnedSocket) -> Self {
368         unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
369     }
370 }
371 
372 #[cfg(any(unix, target_os = "wasi"))]
373 impl AsFd for std::net::UdpSocket {
374     #[inline]
as_fd(&self) -> BorrowedFd<'_>375     fn as_fd(&self) -> BorrowedFd<'_> {
376         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
377     }
378 }
379 
380 #[cfg(windows)]
381 impl AsSocket for std::net::UdpSocket {
382     #[inline]
as_socket(&self) -> BorrowedSocket383     fn as_socket(&self) -> BorrowedSocket {
384         unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) }
385     }
386 }
387 
388 #[cfg(any(unix, target_os = "wasi"))]
389 impl IntoFd for std::net::UdpSocket {
390     #[inline]
into_fd(self) -> OwnedFd391     fn into_fd(self) -> OwnedFd {
392         unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
393     }
394 }
395 
396 #[cfg(any(unix, target_os = "wasi"))]
397 impl From<std::net::UdpSocket> for OwnedFd {
398     #[inline]
from(owned: std::net::UdpSocket) -> Self399     fn from(owned: std::net::UdpSocket) -> Self {
400         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
401     }
402 }
403 
404 #[cfg(windows)]
405 impl IntoSocket for std::net::UdpSocket {
406     #[inline]
into_socket(self) -> OwnedSocket407     fn into_socket(self) -> OwnedSocket {
408         unsafe { OwnedSocket::from_raw_socket(self.into_raw_socket()) }
409     }
410 }
411 
412 #[cfg(windows)]
413 impl From<std::net::UdpSocket> for OwnedSocket {
414     #[inline]
from(owned: std::net::UdpSocket) -> Self415     fn from(owned: std::net::UdpSocket) -> Self {
416         unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
417     }
418 }
419 
420 #[cfg(any(unix, target_os = "wasi"))]
421 impl FromFd for std::net::UdpSocket {
422     #[inline]
from_fd(owned: OwnedFd) -> Self423     fn from_fd(owned: OwnedFd) -> Self {
424         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
425     }
426 }
427 
428 #[cfg(any(unix, target_os = "wasi"))]
429 impl From<OwnedFd> for std::net::UdpSocket {
430     #[inline]
from(owned: OwnedFd) -> Self431     fn from(owned: OwnedFd) -> Self {
432         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
433     }
434 }
435 
436 #[cfg(windows)]
437 impl FromSocket for std::net::UdpSocket {
438     #[inline]
from_socket(owned: OwnedSocket) -> Self439     fn from_socket(owned: OwnedSocket) -> Self {
440         unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
441     }
442 }
443 
444 #[cfg(windows)]
445 impl From<OwnedSocket> for std::net::UdpSocket {
446     #[inline]
from(owned: OwnedSocket) -> Self447     fn from(owned: OwnedSocket) -> Self {
448         unsafe { Self::from_raw_socket(owned.into_raw_socket()) }
449     }
450 }
451 
452 #[cfg(any(unix, target_os = "wasi"))]
453 impl AsFd for std::io::Stdin {
454     #[inline]
as_fd(&self) -> BorrowedFd<'_>455     fn as_fd(&self) -> BorrowedFd<'_> {
456         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
457     }
458 }
459 
460 #[cfg(windows)]
461 impl AsHandle for std::io::Stdin {
462     #[inline]
as_handle(&self) -> BorrowedHandle<'_>463     fn as_handle(&self) -> BorrowedHandle<'_> {
464         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
465     }
466 }
467 
468 #[cfg(any(unix, target_os = "wasi"))]
469 impl<'a> AsFd for std::io::StdinLock<'a> {
470     #[inline]
as_fd(&self) -> BorrowedFd<'_>471     fn as_fd(&self) -> BorrowedFd<'_> {
472         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
473     }
474 }
475 
476 #[cfg(windows)]
477 impl<'a> AsHandle for std::io::StdinLock<'a> {
478     #[inline]
as_handle(&self) -> BorrowedHandle<'_>479     fn as_handle(&self) -> BorrowedHandle<'_> {
480         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
481     }
482 }
483 
484 #[cfg(any(unix, target_os = "wasi"))]
485 impl AsFd for std::io::Stdout {
486     #[inline]
as_fd(&self) -> BorrowedFd<'_>487     fn as_fd(&self) -> BorrowedFd<'_> {
488         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
489     }
490 }
491 
492 #[cfg(windows)]
493 impl AsHandle for std::io::Stdout {
494     #[inline]
as_handle(&self) -> BorrowedHandle<'_>495     fn as_handle(&self) -> BorrowedHandle<'_> {
496         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
497     }
498 }
499 
500 #[cfg(any(unix, target_os = "wasi"))]
501 impl<'a> AsFd for std::io::StdoutLock<'a> {
502     #[inline]
as_fd(&self) -> BorrowedFd<'_>503     fn as_fd(&self) -> BorrowedFd<'_> {
504         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
505     }
506 }
507 
508 #[cfg(windows)]
509 impl<'a> AsHandle for std::io::StdoutLock<'a> {
510     #[inline]
as_handle(&self) -> BorrowedHandle<'_>511     fn as_handle(&self) -> BorrowedHandle<'_> {
512         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
513     }
514 }
515 
516 #[cfg(any(unix, target_os = "wasi"))]
517 impl AsFd for std::io::Stderr {
518     #[inline]
as_fd(&self) -> BorrowedFd<'_>519     fn as_fd(&self) -> BorrowedFd<'_> {
520         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
521     }
522 }
523 
524 #[cfg(windows)]
525 impl AsHandle for std::io::Stderr {
526     #[inline]
as_handle(&self) -> BorrowedHandle<'_>527     fn as_handle(&self) -> BorrowedHandle<'_> {
528         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
529     }
530 }
531 
532 #[cfg(any(unix, target_os = "wasi"))]
533 impl<'a> AsFd for std::io::StderrLock<'a> {
534     #[inline]
as_fd(&self) -> BorrowedFd<'_>535     fn as_fd(&self) -> BorrowedFd<'_> {
536         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
537     }
538 }
539 
540 #[cfg(windows)]
541 impl<'a> AsHandle for std::io::StderrLock<'a> {
542     #[inline]
as_handle(&self) -> BorrowedHandle<'_>543     fn as_handle(&self) -> BorrowedHandle<'_> {
544         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
545     }
546 }
547 
548 #[cfg(unix)]
549 impl AsFd for std::process::ChildStdin {
550     #[inline]
as_fd(&self) -> BorrowedFd<'_>551     fn as_fd(&self) -> BorrowedFd<'_> {
552         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
553     }
554 }
555 
556 #[cfg(windows)]
557 impl AsHandle for std::process::ChildStdin {
558     #[inline]
as_handle(&self) -> BorrowedHandle<'_>559     fn as_handle(&self) -> BorrowedHandle<'_> {
560         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
561     }
562 }
563 
564 #[cfg(unix)]
565 impl IntoFd for std::process::ChildStdin {
566     #[inline]
into_fd(self) -> OwnedFd567     fn into_fd(self) -> OwnedFd {
568         unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
569     }
570 }
571 
572 #[cfg(unix)]
573 impl From<std::process::ChildStdin> for OwnedFd {
574     #[inline]
from(owned: std::process::ChildStdin) -> Self575     fn from(owned: std::process::ChildStdin) -> Self {
576         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
577     }
578 }
579 
580 #[cfg(windows)]
581 impl IntoHandle for std::process::ChildStdin {
582     #[inline]
into_handle(self) -> OwnedHandle583     fn into_handle(self) -> OwnedHandle {
584         unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) }
585     }
586 }
587 
588 #[cfg(windows)]
589 impl From<std::process::ChildStdin> for OwnedHandle {
590     #[inline]
from(owned: std::process::ChildStdin) -> Self591     fn from(owned: std::process::ChildStdin) -> Self {
592         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
593     }
594 }
595 
596 #[cfg(unix)]
597 impl AsFd for std::process::ChildStdout {
598     #[inline]
as_fd(&self) -> BorrowedFd<'_>599     fn as_fd(&self) -> BorrowedFd<'_> {
600         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
601     }
602 }
603 
604 #[cfg(windows)]
605 impl AsHandle for std::process::ChildStdout {
606     #[inline]
as_handle(&self) -> BorrowedHandle<'_>607     fn as_handle(&self) -> BorrowedHandle<'_> {
608         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
609     }
610 }
611 
612 #[cfg(unix)]
613 impl IntoFd for std::process::ChildStdout {
614     #[inline]
into_fd(self) -> OwnedFd615     fn into_fd(self) -> OwnedFd {
616         unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
617     }
618 }
619 
620 #[cfg(unix)]
621 impl From<std::process::ChildStdout> for OwnedFd {
622     #[inline]
from(owned: std::process::ChildStdout) -> Self623     fn from(owned: std::process::ChildStdout) -> Self {
624         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
625     }
626 }
627 
628 #[cfg(windows)]
629 impl IntoHandle for std::process::ChildStdout {
630     #[inline]
into_handle(self) -> OwnedHandle631     fn into_handle(self) -> OwnedHandle {
632         unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) }
633     }
634 }
635 
636 #[cfg(windows)]
637 impl From<std::process::ChildStdout> for OwnedHandle {
638     #[inline]
from(owned: std::process::ChildStdout) -> Self639     fn from(owned: std::process::ChildStdout) -> Self {
640         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
641     }
642 }
643 
644 #[cfg(unix)]
645 impl AsFd for std::process::ChildStderr {
646     #[inline]
as_fd(&self) -> BorrowedFd<'_>647     fn as_fd(&self) -> BorrowedFd<'_> {
648         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
649     }
650 }
651 
652 #[cfg(windows)]
653 impl AsHandle for std::process::ChildStderr {
654     #[inline]
as_handle(&self) -> BorrowedHandle<'_>655     fn as_handle(&self) -> BorrowedHandle<'_> {
656         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
657     }
658 }
659 
660 #[cfg(unix)]
661 impl IntoFd for std::process::ChildStderr {
662     #[inline]
into_fd(self) -> OwnedFd663     fn into_fd(self) -> OwnedFd {
664         unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
665     }
666 }
667 
668 #[cfg(unix)]
669 impl From<std::process::ChildStderr> for OwnedFd {
670     #[inline]
from(owned: std::process::ChildStderr) -> Self671     fn from(owned: std::process::ChildStderr) -> Self {
672         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
673     }
674 }
675 
676 #[cfg(windows)]
677 impl IntoHandle for std::process::ChildStderr {
678     #[inline]
into_handle(self) -> OwnedHandle679     fn into_handle(self) -> OwnedHandle {
680         unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) }
681     }
682 }
683 
684 #[cfg(windows)]
685 impl From<std::process::ChildStderr> for OwnedHandle {
686     #[inline]
from(owned: std::process::ChildStderr) -> Self687     fn from(owned: std::process::ChildStderr) -> Self {
688         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
689     }
690 }
691 
692 #[cfg(unix)]
693 impl FromFd for std::process::Stdio {
694     #[inline]
from_fd(owned: OwnedFd) -> Self695     fn from_fd(owned: OwnedFd) -> Self {
696         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
697     }
698 }
699 
700 #[cfg(unix)]
701 impl From<OwnedFd> for std::process::Stdio {
702     #[inline]
from(owned: OwnedFd) -> Self703     fn from(owned: OwnedFd) -> Self {
704         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
705     }
706 }
707 
708 #[cfg(windows)]
709 impl FromHandle for std::process::Stdio {
710     #[inline]
from_handle(owned: OwnedHandle) -> Self711     fn from_handle(owned: OwnedHandle) -> Self {
712         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
713     }
714 }
715 
716 #[cfg(windows)]
717 impl From<OwnedHandle> for std::process::Stdio {
718     #[inline]
from(owned: OwnedHandle) -> Self719     fn from(owned: OwnedHandle) -> Self {
720         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
721     }
722 }
723 
724 #[cfg(windows)]
725 impl AsHandle for std::process::Child {
726     #[inline]
as_handle(&self) -> BorrowedHandle<'_>727     fn as_handle(&self) -> BorrowedHandle<'_> {
728         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
729     }
730 }
731 
732 #[cfg(windows)]
733 impl IntoHandle for std::process::Child {
734     #[inline]
into_handle(self) -> OwnedHandle735     fn into_handle(self) -> OwnedHandle {
736         unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) }
737     }
738 }
739 
740 #[cfg(windows)]
741 impl From<std::process::Child> for OwnedHandle {
742     #[inline]
from(owned: std::process::Child) -> Self743     fn from(owned: std::process::Child) -> Self {
744         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
745     }
746 }
747 
748 #[cfg(unix)]
749 impl AsFd for std::os::unix::net::UnixStream {
750     #[inline]
as_fd(&self) -> BorrowedFd<'_>751     fn as_fd(&self) -> BorrowedFd<'_> {
752         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
753     }
754 }
755 
756 #[cfg(unix)]
757 impl IntoFd for std::os::unix::net::UnixStream {
758     #[inline]
into_fd(self) -> OwnedFd759     fn into_fd(self) -> OwnedFd {
760         unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
761     }
762 }
763 
764 #[cfg(unix)]
765 impl From<std::os::unix::net::UnixStream> for OwnedFd {
766     #[inline]
from(owned: std::os::unix::net::UnixStream) -> Self767     fn from(owned: std::os::unix::net::UnixStream) -> Self {
768         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
769     }
770 }
771 
772 #[cfg(unix)]
773 impl FromFd for std::os::unix::net::UnixStream {
774     #[inline]
from_fd(owned: OwnedFd) -> Self775     fn from_fd(owned: OwnedFd) -> Self {
776         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
777     }
778 }
779 
780 #[cfg(unix)]
781 impl From<OwnedFd> for std::os::unix::net::UnixStream {
782     #[inline]
from(owned: OwnedFd) -> Self783     fn from(owned: OwnedFd) -> Self {
784         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
785     }
786 }
787 
788 #[cfg(unix)]
789 impl AsFd for std::os::unix::net::UnixListener {
790     #[inline]
as_fd(&self) -> BorrowedFd<'_>791     fn as_fd(&self) -> BorrowedFd<'_> {
792         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
793     }
794 }
795 
796 #[cfg(unix)]
797 impl IntoFd for std::os::unix::net::UnixListener {
798     #[inline]
into_fd(self) -> OwnedFd799     fn into_fd(self) -> OwnedFd {
800         unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
801     }
802 }
803 
804 #[cfg(unix)]
805 impl From<std::os::unix::net::UnixListener> for OwnedFd {
806     #[inline]
from(owned: std::os::unix::net::UnixListener) -> Self807     fn from(owned: std::os::unix::net::UnixListener) -> Self {
808         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
809     }
810 }
811 
812 #[cfg(unix)]
813 impl FromFd for std::os::unix::net::UnixListener {
814     #[inline]
from_fd(owned: OwnedFd) -> Self815     fn from_fd(owned: OwnedFd) -> Self {
816         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
817     }
818 }
819 
820 #[cfg(unix)]
821 impl From<OwnedFd> for std::os::unix::net::UnixListener {
822     #[inline]
from(owned: OwnedFd) -> Self823     fn from(owned: OwnedFd) -> Self {
824         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
825     }
826 }
827 
828 #[cfg(unix)]
829 impl AsFd for std::os::unix::net::UnixDatagram {
830     #[inline]
as_fd(&self) -> BorrowedFd<'_>831     fn as_fd(&self) -> BorrowedFd<'_> {
832         unsafe { BorrowedFd::borrow_raw(self.as_raw_fd()) }
833     }
834 }
835 
836 #[cfg(unix)]
837 impl IntoFd for std::os::unix::net::UnixDatagram {
838     #[inline]
into_fd(self) -> OwnedFd839     fn into_fd(self) -> OwnedFd {
840         unsafe { OwnedFd::from_raw_fd(self.into_raw_fd()) }
841     }
842 }
843 
844 #[cfg(unix)]
845 impl From<std::os::unix::net::UnixDatagram> for OwnedFd {
846     #[inline]
from(owned: std::os::unix::net::UnixDatagram) -> Self847     fn from(owned: std::os::unix::net::UnixDatagram) -> Self {
848         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
849     }
850 }
851 
852 #[cfg(unix)]
853 impl FromFd for std::os::unix::net::UnixDatagram {
854     #[inline]
from_fd(owned: OwnedFd) -> Self855     fn from_fd(owned: OwnedFd) -> Self {
856         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
857     }
858 }
859 
860 #[cfg(unix)]
861 impl From<OwnedFd> for std::os::unix::net::UnixDatagram {
862     #[inline]
from(owned: OwnedFd) -> Self863     fn from(owned: OwnedFd) -> Self {
864         unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
865     }
866 }
867 
868 #[cfg(windows)]
869 impl<T> AsHandle for std::thread::JoinHandle<T> {
870     #[inline]
as_handle(&self) -> BorrowedHandle<'_>871     fn as_handle(&self) -> BorrowedHandle<'_> {
872         unsafe { BorrowedHandle::borrow_raw(self.as_raw_handle()) }
873     }
874 }
875 
876 #[cfg(windows)]
877 impl<T> IntoHandle for std::thread::JoinHandle<T> {
878     #[inline]
into_handle(self) -> OwnedHandle879     fn into_handle(self) -> OwnedHandle {
880         unsafe { OwnedHandle::from_raw_handle(self.into_raw_handle()) }
881     }
882 }
883 
884 #[cfg(windows)]
885 impl<T> From<std::thread::JoinHandle<T>> for OwnedHandle {
886     #[inline]
from(owned: std::thread::JoinHandle<T>) -> Self887     fn from(owned: std::thread::JoinHandle<T>) -> Self {
888         unsafe { Self::from_raw_handle(owned.into_raw_handle()) }
889     }
890 }
891