Skip to main content

Execution

Struct Execution 

Source
pub struct Execution { /* private fields */ }
Expand description

The result of one run of an external command

The value holds the command that ran, the exit status of the command, what the command wrote to its standard output and to its standard error, and the time that the run took. It also holds the identifier that the operating system gave the command. The two streams stay apart, because a program separates its result from its diagnostics.

A status that is not a success is data. The check mode of a formatter ends without success when it finds a file to format, and that is the answer that the caller asked for. A caller that must not accept such a status calls require_success.

§Examples

use kawauso_process::Invocation;

let execution = Invocation::new("git").arg("status").run().await?;

println!("{}", execution.stdout());

Implementations§

Source§

impl Execution

Source

pub fn new( invocation: Invocation, id: Option<ProcessId>, status: ExitStatus, stdout: Capture, stderr: Capture, duration: Duration, ) -> Self

Creates the result of a run

A run builds this value, and a caller builds one where a test stands in for a command that no one starts. The identifier is the one that the operating system gave the command, and a result that no command produced carries none.

Source

pub fn duration(&self) -> Duration

Returns the time that the run took

The time covers the whole run, from the start of the program to the end of the capture. A caller that reports a slow step, or that logs how long a tool ran, reads it here instead of measuring the call.

Source

pub fn id(&self) -> Option<ProcessId>

Returns the identifier that the operating system gave the command

An application that reports which program ran, or that writes the identifier to a log, reads it here. The value is None when no run produced the result, such as a result that a test built.

The command of a result has ended, and the operating system can give the identifier to another command. The value therefore names the command that ran. It does not name a command that runs now.

Source

pub fn invocation(&self) -> &Invocation

Returns the command that ran

Source

pub fn require_success(self) -> Result<Self, RequireSuccessError>

Returns the result of a run that ended with success

A caller that must not accept a command that failed makes the check with this method instead of reading the status itself. The result travels on, so a caller can take the output of the command from it.

§Errors

Returns UnsuccessfulCommand when the command ended without success. The error names the command, the status, and what the command wrote to its standard error, which is where a program states why it stopped.

§Examples
use kawauso_process::Invocation;

let execution = Invocation::new("git")
    .arg("rev-parse")
    .arg("HEAD")
    .run()
    .await?
    .require_success()?;

let commit = execution.stdout().to_string_lossy().trim().to_owned();
Source

pub fn status(&self) -> ExitStatus

Returns the status with which the command ended

A status that is not a success is a normal result. A command that ran and failed reports its failure here, and the run itself returns an error only when the command could not run at all.

Source

pub fn stderr(&self) -> &Capture

Returns what the command wrote to its standard error

Source

pub fn stdout(&self) -> &Capture

Returns what the command wrote to its standard output

Trait Implementations§

Source§

impl Clone for Execution

Source§

fn clone(&self) -> Execution

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 Debug for Execution

Source§

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

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

impl Eq for Execution

Source§

impl PartialEq for Execution

Source§

fn eq(&self, other: &Execution) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Execution

Auto Trait Implementations§

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> 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, 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.