Struct ExitStatusError

pub struct ExitStatusError(pub(in ::process) 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)

Fields

0: ExitStatusError

Implementations

impl ExitStatusError

fn code(&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) -> 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) -> ExitStatus

Converts an ExitStatusError (back) to an ExitStatus.

Trait Implementations

impl Clone for ExitStatusError

fn clone(&self) -> ExitStatusError

impl Copy for ExitStatusError

impl Debug for ExitStatusError

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

impl Display for ExitStatusError

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

impl Eq for ExitStatusError

fn assert_fields_are_eq(&self)

impl Error for ExitStatusError

impl ExitStatusExt for ExitStatusError

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

impl PartialEq for ExitStatusError

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

impl StructuralPartialEq for ExitStatusError

impl TrivialClone for ExitStatusError

Auto Trait Implementations

impl Freeze for ExitStatusError

impl RefUnwindSafe for ExitStatusError

impl Send for ExitStatusError

impl Sync for ExitStatusError

impl Unpin for ExitStatusError

impl UnsafeUnpin for ExitStatusError

impl UnwindSafe for ExitStatusError

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

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

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

impl<T> From<T> for ExitStatusError

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Printable for ExitStatusError where T: Copy + Debug,

impl<T> SizeHint for ExitStatusError where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for ExitStatusError

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

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> ToString for ExitStatusError where T: Display + ?Sized,

fn to_string(&self) -> String

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

fn into(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<U> for ExitStatusError where U: Into<T>,

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

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

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