[][src]Enum mapped_command::ExitStatus

pub enum ExitStatus {
    Code(i64),
    OsSpecific(OpaqueOsExitStatus),
}

A ExitStatus type similar to std::process::ExitStatus but which can be created (e.g. for testing).

Display

If there is an exit code it will always be displayed as hexadecimal. This is done because of two reasons:

  • Some platforms allow rather large exit codes which are just very unreadable (and unrecognizable) in decimal formatting.
  • The hex format is always bit based which removes confusions around differences between targets having signed and unsigned exit codes. The drawback is that on platforms which do allow negative exit codes you need to convert the number not just from hex to decimal but also consider signing wrt. the max supported unsigned size on that platform.

An target specific exit status is displayed in a target specific way. The non os specific fallback defaults to displaying NO_exit_status. A signal termination exit status on unix will be displayed as e.g. signal(9).

Os Support

For now part of this type are only supported for targets of the os families windows and unix(-like).

If you need support for any other OS feel free to open an issue, I will add the necessary code path for the methods which are not OS independent then.

Currently this only affects the ExitStatus::successful() method.

Why not std::process::ExitStatus?

The standard library and this library have different design goals, most importantly this library can introduce braking changes while the standard library ones can't really do so.

Major differences include:

  • Just one enum instead of an .exit_status() -> Option<i32> accessor.
  • Implements PartialEq<RHS> for various numbers making testing easier.
  • Has a platform independent constructor, std::process::ExitStatus has various platform specific constructors.
  • Uses i64 as exit code to more correctly represents exits codes (see below).

Incompatibilities and limitations.

Due to the current structures a various exit codes can be constructed which are not possible to appear on the target you are currently compiling against. This is already true for the std implementation, but with slightly less constraints in our case. For example if you target linux you can still create a exit code > 0xFF but in linux no exit code > 0xFF can be returned ( furthermore returning any exit code > 127 is a cause of unexpected problems and must be avoided).

Furthermore std::process::Command returning a i32 code is a major problem as it's incompatible with various platforms:

  • Windows has a u32! exit code, rust std's Command does reinterpret it as i32 when returning it which in some cases lead to negative exit codes even through there are not negative exit codes on windows. Furthermore Fushisa does have a i64 exit status which they currently can't handle at all. Be aware that this library still uses std::process::Command internally and a such can't handle this either. But we do "fix" the exit code so that an exit code of u32::MAX is still u32::MAX and not -1!.

Variants

Code(i64)

The process exited with an exit code.

As this allows any i64 this allows you to create an exit status which can not appear on the current target. (This is also possible with the standard libraries ExitStatus). This makes testing easier and allows you to test cases of exit codes which can't appear on your but other platforms.

Differences to std::process::ExitStatus

This uses a i64 as this allows a more correct representation of exit codes.

On windows a exit code > i32::MAX will be correctly be represented as such instead of wrongly being displayed as negative number.

OsSpecific(OpaqueOsExitStatus)

An exit status which isn't a simple exit code was returned.

On unix if a process was directly terminated via an signal no exit code was set but the signal causing the exit is returned (encoded with other values in the raw exit status).

Rust represents this separately as depending on the exact unix-like operating system it might be encoded in different ways, in some cases instead of a integer encoding the status a struct with multiple fields is returned, as such there is no correct or reliable way to encode exit an status just as an number.

Be aware that for testability OpaqueOsExitStatus can be created on all platforms even through e.g. on windows there are only exit codes! Note that the exact inner implementation of OpaqueOsExitStatus is platform dependent, but it implements arbitrary_default()

Implementations

impl ExitStatus[src]

pub fn successful(&self) -> bool[src]

Returns true if the command did succeed.

As not all operating systems use 0 == success we need to have platform specific code for all of them. Which is infeasible and as such this is only enabled on the unix and window target family. (Note that windows and unix are currently the only target families as e.g. linux, all BSD's, OsX, iOs are unix-like enough to count as part of the unix family).

Trait Implementations

impl Clone for ExitStatus[src]

impl Copy for ExitStatus[src]

impl Debug for ExitStatus[src]

impl Default for ExitStatus[src]

impl Display for ExitStatus[src]

impl Eq for ExitStatus[src]

impl From<OpaqueOsExitStatus> for ExitStatus[src]

impl From<i16> for ExitStatus[src]

impl From<i32> for ExitStatus[src]

impl From<i64> for ExitStatus[src]

impl From<i8> for ExitStatus[src]

impl From<u16> for ExitStatus[src]

impl From<u32> for ExitStatus[src]

impl From<u8> for ExitStatus[src]

impl Hash for ExitStatus[src]

impl PartialEq<ExitStatus> for ExitStatus[src]

impl PartialEq<i16> for ExitStatus[src]

impl PartialEq<i32> for ExitStatus[src]

impl PartialEq<i64> for ExitStatus[src]

impl PartialEq<i8> for ExitStatus[src]

impl PartialEq<u16> for ExitStatus[src]

impl PartialEq<u32> for ExitStatus[src]

impl PartialEq<u8> for ExitStatus[src]

impl StructuralEq for ExitStatus[src]

impl StructuralPartialEq for ExitStatus[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.