Trait process_control::ChildExt
source · pub trait ChildExt<'a>: Sealed {
type ExitStatusControl: 'a + Control<Result = ExitStatus> + Debug;
type OutputControl: Control<Result = Output> + Debug;
fn terminate_if_running(&mut self) -> Result<()>;
fn controlled(&'a mut self) -> Self::ExitStatusControl;
fn controlled_with_output(self) -> Self::OutputControl;
}Expand description
Extensions to Child for easily terminating processes.
For more information, see the module-level documentation.
Required Associated Types§
sourcetype ExitStatusControl: 'a + Control<Result = ExitStatus> + Debug
type ExitStatusControl: 'a + Control<Result = ExitStatus> + Debug
The type returned by controlled.
sourcetype OutputControl: Control<Result = Output> + Debug
type OutputControl: Control<Result = Output> + Debug
The type returned by controlled_with_output.
Required Methods§
sourcefn terminate_if_running(&mut self) -> Result<()>
fn terminate_if_running(&mut self) -> Result<()>
Equivalent to Child::kill but ignores errors when the process is no
longer running.
Windows and Unix errors are inconsistent when terminating processes. This method unifies them by simulating Unix behavior on Windows.
sourcefn controlled(&'a mut self) -> Self::ExitStatusControl
fn controlled(&'a mut self) -> Self::ExitStatusControl
Creates an instance of Control that yields ExitStatus for this
process.
This method parallels Child::wait but allows setting limits on the
process.
Examples
use std::process::Command;
use std::time::Duration;
use process_control::ChildExt;
use process_control::Control;
let exit_status = Command::new("echo")
.spawn()?
.controlled()
.time_limit(Duration::from_secs(1))
.terminate_for_timeout()
.wait()?
.expect("process timed out");
assert!(exit_status.success());sourcefn controlled_with_output(self) -> Self::OutputControl
fn controlled_with_output(self) -> Self::OutputControl
Creates an instance of Control that yields Output for this
process.
This method parallels Child::wait_with_output but allows setting
limits on the process.
Examples
use std::process::Command;
use std::time::Duration;
use process_control::ChildExt;
use process_control::Control;
let output = Command::new("echo")
.spawn()?
.controlled_with_output()
.time_limit(Duration::from_secs(1))
.terminate_for_timeout()
.wait()?
.expect("process timed out");
assert!(output.status.success());