From 870cd2dc1ffa6ee25b3d393c809c4484c1d9ea58 Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Thu, 27 Jan 2022 20:46:09 +0100 Subject: [PATCH] Impl From for Command Allow creating Command from std::process::Command, similar to what tokio::process::Command supports. --- src/lib.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3e43a34..970a80d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -639,14 +639,7 @@ impl Command { /// let mut cmd = Command::new("ls"); /// ``` pub fn new>(program: S) -> Command { - Command { - inner: std::process::Command::new(program), - stdin: false, - stdout: false, - stderr: false, - reap_on_drop: true, - kill_on_drop: false, - } + Self::from(std::process::Command::new(program)) } /// Adds a single argument to pass to the program. @@ -946,6 +939,19 @@ impl Command { } } +impl From for Command { + fn from(inner: std::process::Command) -> Self { + Self { + inner, + stdin: false, + stdout: false, + stderr: false, + reap_on_drop: true, + kill_on_drop: false, + } + } +} + impl fmt::Debug for Command { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if f.alternate() {