Skip to main content

ProcessResult

Struct ProcessResult 

Source
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>

Source

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.

Source

pub fn stdout(&self) -> &T

The captured standard output (text or bytes depending on T).

Source

pub fn into_stdout(self) -> T

Consume the result and return just the captured standard output.

Source

pub fn stderr(&self) -> &str

The captured standard error.

Source

pub fn outcome(&self) -> Outcome

How the run ended, as the explicit three-way Outcome.

Source

pub fn code(&self) -> Option<i32>

The process exit code, or None when the run yielded no code — killed by its timeout (timed_out is then true) or terminated by a signal on Unix (timed_out is false). There is no synthetic sentinel: a missing code is None, never -1. Derived from outcome.

Source

pub fn timed_out(&self) -> bool

Whether the run was killed because it exceeded its timeout. Derived from outcome.

Source

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.

Source

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.

Source

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).

Source

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).

Source

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>

Source

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.

Source

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,

Source§

fn clone(&self) -> ProcessResult<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for ProcessResult<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Eq for ProcessResult<T>
where T: Eq,

Source§

impl<T> PartialEq for ProcessResult<T>
where T: PartialEq,

Source§

fn eq(&self, other: &ProcessResult<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> Freeze for ProcessResult<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ProcessResult<T>
where T: RefUnwindSafe,

§

impl<T> Send for ProcessResult<T>
where T: Send,

§

impl<T> Sync for ProcessResult<T>
where T: Sync,

§

impl<T> Unpin for ProcessResult<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ProcessResult<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for ProcessResult<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more