pub trait ProcessRunner: Send + Sync {
// Required method
fn output_string<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<ProcessResult<String>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn output_bytes<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<ProcessResult<Vec<u8>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn start<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<RunningProcess>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
Runs a Command — to a captured result (output_string /
output_bytes) or a live handle (start).
This seam is the mock point — only output_string is required
(output_bytes/start are defaulted): production code takes
&dyn ProcessRunner; tests pass a
ScriptedRunner /
RecordingRunner (or, behind the mock feature,
a generated MockRunner) instead of spawning real processes.
The defaulting note above applies to hand-written runners. The
mock-feature MockRunner is different: mockall::automock replaces every
method — including the defaulted output_bytes/start — with an expectation,
so a MockRunner does not inherit the Unsupported default. Set the
expectations you exercise (expect_output_string(), and expect_start() /
expect_output_bytes() if a verb routes through them) or an unset call panics.
ScriptedRunner is the recommended double — it provides the defaults and the
streaming seam out of the box. (The mock feature / MockRunner are
semver-exempt — see the crate-level docs.)
Required Methods§
Sourcefn output_string<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<ProcessResult<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn output_string<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<ProcessResult<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Run command to completion, capturing stdout/stderr and the exit code.
A non-zero exit is reported in the result, not raised.
Provided Methods§
Sourcefn output_bytes<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<ProcessResult<Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn output_bytes<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<ProcessResult<Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Run command to completion, capturing stdout as raw bytes (output_string
captures it as lossy-UTF-8 text); stderr is still text. For binary tools
— git cat-file, tar -c, an image transcoder — whose stdout is not
UTF-8.
Part of the seam (not just Command), so byte-producing tools are
testable through a ScriptedRunner /
&ProcessGroup / JobRunner like text ones. Defaulted in terms of
start — so a runner that overrides start gets byte
capture for free, and an output_string-only runner (one that does not
override start) surfaces Error::Unsupported,
matching start. A text fixture (a record-feature cassette stores
lossy-UTF-8) cannot reproduce exact bytes; capture bytes from a real or
scripted runner.
Sourcefn start<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<RunningProcess>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn start<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<RunningProcess>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Start command and return a live RunningProcess for streaming,
readiness probes, or incremental consumption.
Defaulted to Error::Unsupported so an
output_string-only runner (a hand-rolled double, a cassette runner) keeps
compiling; the real runners (JobRunner, &ProcessGroup) and
ScriptedRunner override it.
This is deliberately a runtime capability (a default that errors)
rather than a compile-time split (e.g. a separate ProcessStarter: ProcessRunner supertrait). The trade-off is intentional: an output-only
runner stays a one-method impl, at the cost that calling a streaming
verb on one surfaces Unsupported at run time instead of failing to
compile. Check RunningProcess support out-of-band if you need the
guarantee statically.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<R: ProcessRunner + ?Sized> ProcessRunner for &R
A shared reference to a runner is itself a runner, so a borrowed
RecordingRunner (or any &R) can be injected
where a ProcessRunner is expected.
impl<R: ProcessRunner + ?Sized> ProcessRunner for &R
A shared reference to a runner is itself a runner, so a borrowed
RecordingRunner (or any &R) can be injected
where a ProcessRunner is expected.
fn output_string<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<ProcessResult<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn output_bytes<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<ProcessResult<Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn start<'life0, 'life1, 'async_trait>(
&'life0 self,
command: &'life1 Command,
) -> Pin<Box<dyn Future<Output = Result<RunningProcess>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Implementors§
impl ProcessRunner for JobRunner
impl ProcessRunner for MockProcessRunner
Runs a Command — to a captured result (output_string /
output_bytes) or a live handle (start).
This seam is the mock point — only output_string is required
(output_bytes/start are defaulted): production code takes
&dyn ProcessRunner; tests pass a
ScriptedRunner /
RecordingRunner (or, behind the mock feature,
a generated MockRunner) instead of spawning real processes.
The defaulting note above applies to hand-written runners. The
mock-feature MockRunner is different: mockall::automock replaces every
method — including the defaulted output_bytes/start — with an expectation,
so a MockRunner does not inherit the Unsupported default. Set the
expectations you exercise (expect_output_string(), and expect_start() /
expect_output_bytes() if a verb routes through them) or an unset call panics.
ScriptedRunner is the recommended double — it provides the defaults and the
streaming seam out of the box. (The mock feature / MockRunner are
semver-exempt — see the crate-level docs.)
impl ProcessRunner for ProcessGroup
impl ProcessRunner for ScriptedRunner
impl<R: ProcessRunner> ProcessRunner for RecordReplayRunner<R>
record only.