pub trait CommandExecutor {
// Required methods
fn status(&self, cmd: &mut Command) -> Result<ExitStatus>;
fn output(&self, cmd: &mut Command) -> Result<Output>;
// Provided methods
fn execute<F>(&self, builder: F, program: &str) -> Result<Output>
where F: FnOnce(&mut Command) -> &mut Command { ... }
fn run<F>(&self, builder: F, program: &str) -> Result<ExitStatus>
where F: FnOnce(&mut Command) -> &mut Command { ... }
}Expand description
Trait for abstracting command execution.
This trait allows for dependency injection of command execution operations, enabling testing without running real commands and allowing for alternative implementations (e.g., mocked execution, remote execution, etc.).
Required Methods§
Sourcefn status(&self, cmd: &mut Command) -> Result<ExitStatus>
fn status(&self, cmd: &mut Command) -> Result<ExitStatus>
Execute a command and return its exit status. This is the primary method used by the pipeline for running external tools.
Provided Methods§
Sourcefn execute<F>(&self, builder: F, program: &str) -> Result<Output>
fn execute<F>(&self, builder: F, program: &str) -> Result<Output>
Execute a command built with a closure and return its output.
This provides a more ergonomic API for building and executing commands:
§Examples
use wasm_slim::infra::{CommandExecutor, RealCommandExecutor};
use std::process::Command;
let executor = RealCommandExecutor;
let output = executor.execute(|cmd| {
cmd.arg("--version")
.env("RUST_LOG", "debug")
}, "cargo")?;Sourcefn run<F>(&self, builder: F, program: &str) -> Result<ExitStatus>
fn run<F>(&self, builder: F, program: &str) -> Result<ExitStatus>
Execute a command built with a closure and return its exit status.
Similar to execute() but only returns the exit status without capturing output.
§Examples
use wasm_slim::infra::{CommandExecutor, RealCommandExecutor};
use std::process::Command;
let executor = RealCommandExecutor;
let status = executor.run(|cmd| {
cmd.arg("build")
.arg("--release")
}, "cargo")?;Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.