]> git.lizzy.rs Git - rust.git/blobdiff - library/std/src/process.rs
Auto merge of #96820 - r-raymond:master, r=cuviper
[rust.git] / library / std / src / process.rs
index e733766741d5e9ccd4fa3442507b6ac8e43a0830..ab1a1e6c76fa4566c02aea580114d673e64150d8 100644 (file)
@@ -1273,6 +1273,22 @@ pub fn inherit() -> Stdio {
     pub fn null() -> Stdio {
         Stdio(imp::Stdio::Null)
     }
+
+    /// Returns `true` if this requires [`Command`] to create a new pipe.
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// #![feature(stdio_makes_pipe)]
+    /// use std::process::Stdio;
+    ///
+    /// let io = Stdio::piped();
+    /// assert_eq!(io.makes_pipe(), true);
+    /// ```
+    #[unstable(feature = "stdio_makes_pipe", issue = "98288")]
+    pub fn makes_pipe(&self) -> bool {
+        matches!(self.0, imp::Stdio::MakePipe)
+    }
 }
 
 impl FromInner<imp::Stdio> for Stdio {
@@ -2140,16 +2156,6 @@ fn report(self) -> ExitCode {
     }
 }
 
-#[stable(feature = "termination_trait_lib", since = "1.61.0")]
-impl<E: fmt::Debug> Termination for Result<(), E> {
-    fn report(self) -> ExitCode {
-        match self {
-            Ok(()) => ().report(),
-            Err(err) => Err::<!, _>(err).report(),
-        }
-    }
-}
-
 #[stable(feature = "termination_trait_lib", since = "1.61.0")]
 impl Termination for ! {
     fn report(self) -> ExitCode {
@@ -2158,28 +2164,31 @@ fn report(self) -> ExitCode {
 }
 
 #[stable(feature = "termination_trait_lib", since = "1.61.0")]
-impl<E: fmt::Debug> Termination for Result<!, E> {
+impl Termination for Infallible {
     fn report(self) -> ExitCode {
-        let Err(err) = self;
-        // Ignore error if the write fails, for example because stderr is
-        // already closed. There is not much point panicking at this point.
-        let _ = writeln!(io::stderr(), "Error: {err:?}");
-        ExitCode::FAILURE
+        match self {}
     }
 }
 
 #[stable(feature = "termination_trait_lib", since = "1.61.0")]
-impl<E: fmt::Debug> Termination for Result<Infallible, E> {
+impl Termination for ExitCode {
+    #[inline]
     fn report(self) -> ExitCode {
-        let Err(err) = self;
-        Err::<!, _>(err).report()
+        self
     }
 }
 
 #[stable(feature = "termination_trait_lib", since = "1.61.0")]
-impl Termination for ExitCode {
-    #[inline]
+impl<T: Termination, E: fmt::Debug> Termination for Result<T, E> {
     fn report(self) -> ExitCode {
-        self
+        match self {
+            Ok(val) => val.report(),
+            Err(err) => {
+                // Ignore error if the write fails, for example because stderr is
+                // already closed. There is not much point panicking at this point.
+                let _ = writeln!(io::stderr(), "Error: {err:?}");
+                ExitCode::FAILURE
+            }
+        }
     }
 }