Implement From<OwnedFd/Handle> for ChildStdin/out/err object by vthib · Pull Request #98704 · rust-lang/rust (original) (raw)

Summary

Comments in library/std/src/process.rs ( ab08639 ) indicates that ChildStdin, ChildStdout, ChildStderr implements some traits that are not actually implemented: FromRawFd, FromRawHandle, and the From<OwnedFd>/From<OwnedHandle> from the io_safety feature.

In this PR I implement FromRawHandle and FromRawFd for those 3 objects.

Usecase

I have a usecase where those implementations are basically needed. I want to customize
in the Command::spawn API how the pipes for the parent/child communications are created (mainly to strengthen the security attributes on them). I can properly setup the pipes,
and the "child" handles can be provided to Child::spawn easily using Stdio::from_raw_handle. However, there is no way to generate the ChildStd* objects from the raw handle of the created name pipe, which would be very useful to still expose the same API
than in other OS (basically a spawn(...) -> (Child, ChildStdin, ChildStdout, ChildSterr), where on windows this is customized), and to for example use tokio::ChildStdin::from_std afterwards.

Questions