Struct ExitStatusError

struct ExitStatusError(_)

Describes the result of a process after it has failed

Produced by the .exit_ok method on ExitStatus.

Examples

#![feature(exit_status_error)]
# if cfg!(all(unix, not(target_os = "android"), not(all(target_vendor = "apple", not(target_os = "macos"))))) {
use std::process::{Command, ExitStatusError};

fn run(cmd: &str) -> Result<(), ExitStatusError> {
    Command::new(cmd).status().unwrap().exit_ok()?;
    Ok(())
}

run("true").unwrap();
run("false").unwrap_err();
# } // cfg!(unix)

Implementations

impl ExitStatusError

fn code(self: &Self) -> Option<i32>

Reports the exit code, if applicable, from an ExitStatusError.

In Unix terms the return value is the exit status: the value passed to exit, if the process finished by calling exit. Note that on Unix the exit status is truncated to 8 bits, and that values that didn't come from a program's call to exit may be invented by the runtime system (often, for example, 255, 254, 127 or 126).

On Unix, this will return None if the process was terminated by a signal. If you want to handle such situations specially, consider using methods from ExitStatusExt.

If the process finished by calling exit with a nonzero value, this will return that exit status.

If the error was something else, it will return None.

If the process exited successfully (ie, by calling exit(0)), there is no ExitStatusError. So the return value from ExitStatusError::code() is always nonzero.

Examples

#![feature(exit_status_error)]
# #[cfg(all(unix, not(target_os = "android"), not(all(target_vendor = "apple", not(target_os = "macos")))))] {
use std::process::Command;

let bad = Command::new("false").status().unwrap().exit_ok().unwrap_err();
assert_eq!(bad.code(), Some(1));
# } // #[cfg(unix)]
fn code_nonzero(self: &Self) -> Option<NonZero<i32>>

Reports the exit code, if applicable, from an ExitStatusError, as a NonZero.

This is exactly like code(), except that it returns a [NonZero]<[i32]>.

Plain code, returning a plain integer, is provided because it is often more convenient. The returned value from code() is indeed also nonzero; use code_nonzero() when you want a type-level guarantee of nonzeroness.

Examples

#![feature(exit_status_error)]

# if cfg!(all(unix, not(target_os = "android"), not(all(target_vendor = "apple", not(target_os = "macos"))))) {
use std::num::NonZero;
use std::process::Command;

let bad = Command::new("false").status().unwrap().exit_ok().unwrap_err();
assert_eq!(bad.code_nonzero().unwrap(), NonZero::new(1).unwrap());
# } // cfg!(unix)
fn into_status(self: &Self) -> ExitStatus

Converts an ExitStatusError (back) to an ExitStatus.

impl Clone for ExitStatusError

fn clone(self: &Self) -> ExitStatusError

impl Copy for ExitStatusError

impl Debug for ExitStatusError

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

impl Display for ExitStatusError

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

impl Eq for ExitStatusError

impl Error for ExitStatusError

impl ExitStatusExt for process::ExitStatusError

fn from_raw(raw: i32) -> Self
fn signal(self: &Self) -> Option<i32>
fn core_dumped(self: &Self) -> bool
fn stopped_signal(self: &Self) -> Option<i32>
fn continued(self: &Self) -> bool
fn into_raw(self: Self) -> i32

impl Freeze for ExitStatusError

impl PartialEq for ExitStatusError

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

impl RefUnwindSafe for ExitStatusError

impl Send for ExitStatusError

impl StructuralPartialEq for ExitStatusError

impl Sync for ExitStatusError

impl Unpin for ExitStatusError

impl UnwindSafe for ExitStatusError

impl<T> Any for ExitStatusError

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ExitStatusError

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for ExitStatusError

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

impl<T> CloneToUninit for ExitStatusError

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

impl<T> From for ExitStatusError

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for ExitStatusError

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> ToString for ExitStatusError

fn to_string(self: &Self) -> String

impl<T, U> Into for ExitStatusError

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for ExitStatusError

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

impl<T, U> TryInto for ExitStatusError

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