pub trait CommandRunner: Send + Sync {
// Required method
fn run(
&self,
program: &str,
args: &[&str],
cwd: &Path,
) -> Result<CommandOutput, CommandError>;
// Provided methods
fn run_with_timeout(
&self,
program: &str,
args: &[&str],
cwd: &Path,
_timeout: Duration,
) -> Result<CommandOutput, CommandError> { ... }
fn run_quiet(
&self,
program: &str,
args: &[&str],
cwd: &Path,
timeout: Duration,
) -> Result<CommandOutput, CommandError> { ... }
}Expand description
Trait for executing subprocess commands.
Required Methods§
fn run( &self, program: &str, args: &[&str], cwd: &Path, ) -> Result<CommandOutput, CommandError>
Provided Methods§
Sourcefn run_with_timeout(
&self,
program: &str,
args: &[&str],
cwd: &Path,
_timeout: Duration,
) -> Result<CommandOutput, CommandError>
fn run_with_timeout( &self, program: &str, args: &[&str], cwd: &Path, _timeout: Duration, ) -> Result<CommandOutput, CommandError>
Run a command with a hard wall-clock timeout. If the process does not
exit before timeout elapses it is killed and
CommandError::TimedOut is returned.
The default implementation ignores timeout and delegates to Self::run.
Implementors that control a real subprocess should override this with an
actual deadline check.
Sourcefn run_quiet(
&self,
program: &str,
args: &[&str],
cwd: &Path,
timeout: Duration,
) -> Result<CommandOutput, CommandError>
fn run_quiet( &self, program: &str, args: &[&str], cwd: &Path, timeout: Duration, ) -> Result<CommandOutput, CommandError>
Like Self::run_with_timeout, but for an internal existence/probe
check whose stderr is expected to look like a failure on the common
path (e.g. npm view against an unpublished package prints a
404-shaped error to stderr as its normal “not found” signal) –
unlike a real, user-facing mutating command, this must not stream
that noise live to the terminal, only capture it into the returned
CommandOutput for the caller to classify.
The default implementation just delegates to Self::run_with_timeout
(streams live, same as any other command); implementors backed by a
real subprocess and doing their own live-streaming should override
this to suppress it for probe calls specifically.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".