diff --git a/src/child_context.rs b/src/child_context.rs index 169e2fe..fab6842 100644 --- a/src/child_context.rs +++ b/src/child_context.rs @@ -23,6 +23,11 @@ pub struct ChildContext { } impl ChildContext { + /// Construct a new [`ChildContext`]. + pub fn new(child: C, command: Box) -> Self { + Self { child, command } + } + /// Get the child process. pub fn into_child(self) -> C { self.child diff --git a/src/command_ext.rs b/src/command_ext.rs index 241bab3..42e2881 100644 --- a/src/command_ext.rs +++ b/src/command_ext.rs @@ -545,10 +545,7 @@ impl CommandExt for Command { fn spawn_checked(&mut self) -> Result { let displayed: Utf8ProgramAndArgs = (&*self).into(); match self.spawn() { - Ok(child) => Ok(ChildContext { - child, - command: Box::new(displayed), - }), + Ok(child) => Ok(ChildContext::new(child, Box::new(displayed))), Err(inner) => Err(Error::from(ExecError::new(Box::new(displayed), inner))), } } diff --git a/src/process_wrap.rs b/src/process_wrap.rs index f63c9eb..5e10c66 100644 --- a/src/process_wrap.rs +++ b/src/process_wrap.rs @@ -83,10 +83,7 @@ impl CommandExt for StdCommandWrap { fn spawn_checked(&mut self) -> Result { let displayed: Utf8ProgramAndArgs = self.command().into(); match self.spawn() { - Ok(child) => Ok(ChildContext { - child, - command: Box::new(displayed), - }), + Ok(child) => Ok(ChildContext::new(child, Box::new(displayed))), Err(inner) => Err(Error::from(ExecError::new(Box::new(displayed), inner))), } }