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, otherwise the matching
error: Error::Timeout if the run was killed by its deadline (checked
first), Error::Signalled if it was terminated
by a signal (no exit code), else Error::Exit for an exit code outside
the accepted set (code 0 by default — see
Command::ok_codes), carrying the code and
both captured streams in full (the Display impl
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, joined — handy when a tool interleaves diagnostics across both streams.
A \n separator is inserted between the streams when stdout is
non-empty and does not already end with a newline, preventing the last
stdout line from being glued to the first stderr line.
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 moreSource§impl<T> Debug for ProcessResult<T>where
T: Debug,
impl<T> Debug for ProcessResult<T>where
T: Debug,
impl<T> Eq for ProcessResult<T>where
T: Eq,
Source§impl<T> PartialEq for ProcessResult<T>where
T: PartialEq,
impl<T> PartialEq for ProcessResult<T>where
T: PartialEq,
Source§fn eq(&self, other: &ProcessResult<T>) -> bool
fn eq(&self, other: &ProcessResult<T>) -> bool
self and other values to be equal, and is used by ==.