[−][src]Enum checked_command::ExitStatus
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 asi32
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 usesstd::process::Command
internally and a such can't handle this either. But we do "fix" the exit code so that an exit code ofu32::MAX
is stillu32::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]
pub fn clone(&self) -> ExitStatus
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[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]
pub fn from(ooes: OpaqueOsExitStatus) -> Self
[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]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<ExitStatus> for ExitStatus
[src]
pub fn eq(&self, other: &ExitStatus) -> bool
[src]
pub fn ne(&self, other: &ExitStatus) -> bool
[src]
impl PartialEq<i16> for ExitStatus
[src]
pub fn eq(&self, other: &i16) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<i32> for ExitStatus
[src]
pub fn eq(&self, other: &i32) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<i64> for ExitStatus
[src]
pub fn eq(&self, other: &i64) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<i8> for ExitStatus
[src]
impl PartialEq<u16> for ExitStatus
[src]
pub fn eq(&self, other: &u16) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<u32> for ExitStatus
[src]
pub fn eq(&self, other: &u32) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<u8> for ExitStatus
[src]
impl StructuralEq for ExitStatus
[src]
impl StructuralPartialEq for ExitStatus
[src]
Auto Trait Implementations
impl RefUnwindSafe for ExitStatus
[src]
impl Send for ExitStatus
[src]
impl Sync for ExitStatus
[src]
impl Unpin for ExitStatus
[src]
impl UnwindSafe for ExitStatus
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,