pub struct ProcessResult<T> { /* private fields */ }Expand description
The captured result of running a process to completion.
T is the standard-output payload: String for the text helpers
(output_string) or Vec<u8> for the raw-bytes helper (output_bytes).
Standard error is always captured as text. A non-zero exit code is not
treated as an error on its own — inspect code or call
ensure_success.
#[must_use]: the result is the exit status — dropping it unread discards
the only signal that the command failed. Call
is_success / code /
ensure_success. If you only need the side effect,
prefer a verb that never produces a result to discard —
run_unit (error-or-()) or
exit_code — rather than capturing and binding
to let _.
Implementations§
Source§impl<T> ProcessResult<T>
impl<T> ProcessResult<T>
Sourcepub fn program(&self) -> &str
pub fn program(&self) -> &str
The program this result is attributed to (lossy UTF-8 of the program
name) — the same value the error variants carry. For a
Pipeline outcome this is the pipefail-attributed
stage: the first stage that didn’t exit cleanly, or the last stage
when every stage succeeded.
Sourcepub fn into_stdout(self) -> T
pub fn into_stdout(self) -> T
Consume the result and return just the captured standard output.
Sourcepub fn timed_out(&self) -> bool
pub fn timed_out(&self) -> bool
Whether the run was killed because it exceeded its timeout. Derived
from outcome.
Sourcepub fn signal(&self) -> Option<i32>
pub fn signal(&self) -> Option<i32>
The signal number if the process was terminated by a signal with a known
number (Unix only; None otherwise — a clean exit, a timeout, or a
signal the kernel did not expose). Derived from outcome;
the Outcome-level twin is Outcome::signal.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Whether the process exited with an accepted code — 0 by default, or
any code in the set configured via
Command::ok_codes.
Sourcepub fn ensure_success(self) -> Result<ProcessResult<T>, Error>where
T: StdoutText,
pub fn ensure_success(self) -> Result<ProcessResult<T>, Error>where
T: StdoutText,
Return self unchanged when the run succeeded — an accepted exit code
(0 by default; see Command::ok_codes) —
otherwise the matching error.
§Errors
Error::Timeoutif the run was killed by its deadline (checked first, so a run that both timed out and exited non-zero reports the timeout).Error::Signalledif it was terminated by a signal, with no exit code.Error::Exitfor an exit code outside the accepted set, carrying the code and both captured streams in full (theDisplayimpl bounds what it prints; the fields stay complete for classification).
Sourcepub fn duration(&self) -> Duration
pub fn duration(&self) -> Duration
The wall-clock duration of the run — spawn to exit (or kill). It is
Duration::ZERO for synthetic results that didn’t time a real process
(a scripted/replayed bulk output_string).
Sourcepub fn truncated(&self) -> bool
pub fn truncated(&self) -> bool
Whether a bounded OutputBufferPolicy
discarded captured output lines (one or more lines were dropped by the
buffer policy). Lines a streaming consumer popped are not truncation, so
this stays false under the default unbounded policy even after a partial
stdout_lines stream, and for the
raw stdout of output_bytes (not
line-buffered).
Source§impl ProcessResult<String>
impl ProcessResult<String>
Sourcepub fn combined(&self) -> String
pub fn combined(&self) -> String
Standard output followed by standard error, concatenated — handy when a
tool splits diagnostics across both streams. This is stdout then stderr
(each captured in full), not a temporal interleaving of the two — the
crate captures the streams separately, so their relative ordering is not
preserved.
A \n separator is inserted between them only when both streams are
non-empty and stdout does not already end with a newline, preventing the
last stdout line from being glued to the first stderr line. (Matches
Error::combined.)
Sourcepub fn output_contains_any(
&self,
needles: impl IntoIterator<Item = impl AsRef<str>>,
) -> bool
pub fn output_contains_any( &self, needles: impl IntoIterator<Item = impl AsRef<str>>, ) -> bool
Whether either captured stream contains any of needles, matched
case-insensitively (ASCII). For the lenient “a specific non-zero exit
is benign when a known stderr/stdout marker is present” idiom — e.g. gh’s
"no checks reported" or jj’s "no conflicts" — without re-lowercasing a
stream by hand each time. Allocation-free (it never materializes a
lowercased copy of a possibly-large captured stream). The two streams are
searched independently, so a needle never matches across the stdout/stderr
boundary. An empty needles iterator is false; an empty "" needle
follows str::contains (always present).
Accepts any iterable of string-like items — &["a", "b"], Vec<String>,
a single ["a"] array, … — matching the other multi-input builders
(Command::args,
Command::envs).
Sourcepub fn diagnostic(&self) -> &str
pub fn diagnostic(&self) -> &str
The best human-facing message from a captured run, trimmed of surrounding
whitespace: standard error if it carries text, otherwise standard output —
git/jj put CONFLICT … and nothing to commit on stdout, so a probe
that captured the result (rather than erroring) can build the same friendly
message Error::diagnostic gives the erroring
path. For the raw, untrimmed streams use stdout /
stderr.
Trait Implementations§
Source§impl<T> Clone for ProcessResult<T>where
T: Clone,
impl<T> Clone for ProcessResult<T>where
T: Clone,
Source§fn clone(&self) -> ProcessResult<T>
fn clone(&self) -> ProcessResult<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more