Add I/O safety trait impls for process::Stdio and process::Child.

This commit is contained in:
Dan Gohman 2021-08-17 16:28:00 -07:00
parent 6f872880b4
commit 187ee5c824
2 changed files with 36 additions and 2 deletions

View File

@ -4,7 +4,7 @@
use crate::ffi::OsStr;
use crate::io;
use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
use crate::process;
use crate::sealed::Sealed;
use crate::sys;
@ -327,6 +327,16 @@ impl FromRawFd for process::Stdio {
}
}
#[unstable(feature = "io_safety", issue = "87074")]
impl From<OwnedFd> for process::Stdio {
#[inline]
fn from(fd: OwnedFd) -> process::Stdio {
let fd = sys::fd::FileDesc::from_inner(fd);
let io = sys::process::Stdio::Fd(fd);
process::Stdio::from_inner(io)
}
}
#[stable(feature = "process_extensions", since = "1.2.0")]
impl AsRawFd for process::ChildStdin {
#[inline]

View File

@ -3,7 +3,7 @@
#![stable(feature = "process_extensions", since = "1.2.0")]
use crate::ffi::OsStr;
use crate::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle};
use crate::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, OwnedHandle, RawHandle};
use crate::process;
use crate::sealed::Sealed;
use crate::sys;
@ -18,6 +18,15 @@ impl FromRawHandle for process::Stdio {
}
}
#[unstable(feature = "io_safety", issue = "87074")]
impl From<OwnedHandle> for process::Stdio {
fn from(handle: OwnedHandle) -> process::Stdio {
let handle = sys::handle::Handle::from_handle(handle);
let io = sys::process::Stdio::Handle(handle);
process::Stdio::from_inner(io)
}
}
#[stable(feature = "process_extensions", since = "1.2.0")]
impl AsRawHandle for process::Child {
#[inline]
@ -26,6 +35,14 @@ impl AsRawHandle for process::Child {
}
}
#[unstable(feature = "io_safety", issue = "87074")]
impl AsHandle for process::Child {
#[inline]
fn as_handle(&self) -> BorrowedHandle<'_> {
self.as_inner().handle().as_handle()
}
}
#[stable(feature = "into_raw_os", since = "1.4.0")]
impl IntoRawHandle for process::Child {
fn into_raw_handle(self) -> RawHandle {
@ -33,6 +50,13 @@ impl IntoRawHandle for process::Child {
}
}
#[unstable(feature = "io_safety", issue = "87074")]
impl IntoHandle for process::Child {
fn into_handle(self) -> BorrowedHandle<'_> {
self.into_inner().into_handle().into_handle()
}
}
#[stable(feature = "process_extensions", since = "1.2.0")]
impl AsRawHandle for process::ChildStdin {
#[inline]