diff options
| author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2021-09-01 16:39:02 +0100 |
|---|---|---|
| committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2023-08-07 15:18:58 +0100 |
| commit | 36295fad122fd7b94d46f7bcc83a7432b94aee96 (patch) | |
| tree | d053a8dca2db61022baf27a234abf5df3987db0b | |
| parent | 1bab95bf7f82a56cef02299dcc7b12e68daf4c51 (diff) | |
| download | rust-36295fad122fd7b94d46f7bcc83a7432b94aee96.tar.gz rust-36295fad122fd7b94d46f7bcc83a7432b94aee96.zip | |
std::process: impl From<io::Stdout> (etc.) for Stdio
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
| -rw-r--r-- | library/std/src/process.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 8f3201b0091..c9dfd300844 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1491,6 +1491,66 @@ impl From<fs::File> for Stdio { } } +#[stable(feature = "stdio_from_stdio", since = "CURRENT_RUSTC_VERSION")] +impl From<io::Stdout> for Stdio { + /// Redirect command stdout/stderr to our stdout + /// + /// # Examples + /// + /// ```rust + /// #![feature(exit_status_error)] + /// use std::io; + /// use std::process::Command; + /// + /// # fn test() -> Result<(), Box<dyn std::error::Error>> { + /// let output = Command::new("whoami") + // "whoami" is a command which exists on both Unix and Windows, + // and which succeeds, producing some stdout output but no stderr. + /// .stdout(io::stdout()) + /// .output()?; + /// output.status.exit_ok()?; + /// assert!(output.stdout.is_empty()); + /// # Ok(()) + /// # } + /// # + /// # if cfg!(unix) { + /// # test().unwrap(); + /// # } + /// ``` + fn from(inherit: io::Stdout) -> Stdio { + Stdio::from_inner(inherit.into()) + } +} + +#[stable(feature = "stdio_from_stdio", since = "CURRENT_RUSTC_VERSION")] +impl From<io::Stderr> for Stdio { + /// Redirect command stdout/stderr to our stderr + /// + /// # Examples + /// + /// ```rust + /// #![feature(exit_status_error)] + /// use std::io; + /// use std::process::Command; + /// + /// # fn test() -> Result<(), Box<dyn std::error::Error>> { + /// let output = Command::new("whoami") + /// .stdout(io::stderr()) + /// .output()?; + /// output.status.exit_ok()?; + /// assert!(output.stdout.is_empty()); + /// # Ok(()) + /// # } + /// # + /// # if cfg!(unix) { + /// # test().unwrap(); + /// # } + /// ``` + fn from(inherit: io::Stderr) -> Stdio { + Stdio::from_inner(inherit.into()) + } +} + /// Describes the result of a process after it has terminated. /// /// This `struct` is used to represent the exit status or other termination of a child process. |
