Skip to content

Commit 187ee5c

Browse files
committed
Add I/O safety trait impls for process::Stdio and process::Child.
1 parent 6f87288 commit 187ee5c

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

library/std/src/os/unix/process.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use crate::ffi::OsStr;
66
use crate::io;
7-
use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
7+
use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
88
use crate::process;
99
use crate::sealed::Sealed;
1010
use crate::sys;
@@ -327,6 +327,16 @@ impl FromRawFd for process::Stdio {
327327
}
328328
}
329329

330+
#[unstable(feature = "io_safety", issue = "87074")]
331+
impl From<OwnedFd> for process::Stdio {
332+
#[inline]
333+
fn from(fd: OwnedFd) -> process::Stdio {
334+
let fd = sys::fd::FileDesc::from_inner(fd);
335+
let io = sys::process::Stdio::Fd(fd);
336+
process::Stdio::from_inner(io)
337+
}
338+
}
339+
330340
#[stable(feature = "process_extensions", since = "1.2.0")]
331341
impl AsRawFd for process::ChildStdin {
332342
#[inline]

library/std/src/os/windows/process.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![stable(feature = "process_extensions", since = "1.2.0")]
44

55
use crate::ffi::OsStr;
6-
use crate::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle};
6+
use crate::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, OwnedHandle, RawHandle};
77
use crate::process;
88
use crate::sealed::Sealed;
99
use crate::sys;
@@ -18,6 +18,15 @@ impl FromRawHandle for process::Stdio {
1818
}
1919
}
2020

21+
#[unstable(feature = "io_safety", issue = "87074")]
22+
impl From<OwnedHandle> for process::Stdio {
23+
fn from(handle: OwnedHandle) -> process::Stdio {
24+
let handle = sys::handle::Handle::from_handle(handle);
25+
let io = sys::process::Stdio::Handle(handle);
26+
process::Stdio::from_inner(io)
27+
}
28+
}
29+
2130
#[stable(feature = "process_extensions", since = "1.2.0")]
2231
impl AsRawHandle for process::Child {
2332
#[inline]
@@ -26,13 +35,28 @@ impl AsRawHandle for process::Child {
2635
}
2736
}
2837

38+
#[unstable(feature = "io_safety", issue = "87074")]
39+
impl AsHandle for process::Child {
40+
#[inline]
41+
fn as_handle(&self) -> BorrowedHandle<'_> {
42+
self.as_inner().handle().as_handle()
43+
}
44+
}
45+
2946
#[stable(feature = "into_raw_os", since = "1.4.0")]
3047
impl IntoRawHandle for process::Child {
3148
fn into_raw_handle(self) -> RawHandle {
3249
self.into_inner().into_handle().into_raw_handle() as *mut _
3350
}
3451
}
3552

53+
#[unstable(feature = "io_safety", issue = "87074")]
54+
impl IntoHandle for process::Child {
55+
fn into_handle(self) -> BorrowedHandle<'_> {
56+
self.into_inner().into_handle().into_handle()
57+
}
58+
}
59+
3660
#[stable(feature = "process_extensions", since = "1.2.0")]
3761
impl AsRawHandle for process::ChildStdin {
3862
#[inline]

0 commit comments

Comments
 (0)