diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-02-09 14:12:17 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-09 14:12:17 +0900 |
| commit | ec2fd8a35fcd271458dc5fa462ef74bcb372f6c7 (patch) | |
| tree | d1517ec0ba8ac5e9c8ce873cb63d7c0e75d6c437 /library/std/src/sys | |
| parent | 9a5a961be97f405e751dd2cf966e1cdb80a612c2 (diff) | |
| parent | 4c5a36e2d1ac0c5d86ba0a75426d601e7c9202b0 (diff) | |
| download | rust-ec2fd8a35fcd271458dc5fa462ef74bcb372f6c7.tar.gz rust-ec2fd8a35fcd271458dc5fa462ef74bcb372f6c7.zip | |
Rollup merge of #93445 - yaahc:exitcode-constructor, r=dtolnay
Add From<u8> for ExitCode This should cover a mostly cross-platform subset of supported exit codes. We decided to stick with `u8` initially since its the common subset between all platforms that we support (excluding wasm which I think only works with `true` or `false`). Posix is supposed to take i32s, but in practice many unix platforms mask out all but the low 8 bits or in some cases the 8-15th bits. Windows takes a u32 instead of an i32. Bourne-compatible shells also report signals as exitcode 128 + `signal_no`, so there's some ambiguity there when returning exit codes > 127, but it is possible to disambiguate them on the other side so we decided against restricting the possible codes further than to `u8`. ## Related - Detailed analysis of exit code support on various platforms: https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426 - https://github.com/rust-lang/rust/issues/48711 - https://github.com/rust-lang/rust/issues/43301 - https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization
Diffstat (limited to 'library/std/src/sys')
| -rw-r--r-- | library/std/src/sys/unix/process/process_common.rs | 6 | ||||
| -rw-r--r-- | library/std/src/sys/unsupported/process.rs | 9 | ||||
| -rw-r--r-- | library/std/src/sys/windows/process.rs | 6 |
3 files changed, 21 insertions, 0 deletions
diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 7ac2f9d8af7..97985ddd331 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -476,6 +476,12 @@ impl ExitCode { } } +impl From<u8> for ExitCode { + fn from(code: u8) -> Self { + Self(code) + } +} + pub struct CommandArgs<'a> { iter: crate::slice::Iter<'a, CString>, } diff --git a/library/std/src/sys/unsupported/process.rs b/library/std/src/sys/unsupported/process.rs index 7846e43cfb5..42a1ff730e3 100644 --- a/library/std/src/sys/unsupported/process.rs +++ b/library/std/src/sys/unsupported/process.rs @@ -162,6 +162,15 @@ impl ExitCode { } } +impl From<u8> for ExitCode { + fn from(code: u8) -> Self { + match code { + 0 => Self::SUCCESS, + 1..=255 => Self::FAILURE, + } + } +} + pub struct Process(!); impl Process { diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index c6f641d0932..7bfcac8de17 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -666,6 +666,12 @@ impl ExitCode { } } +impl From<u8> for ExitCode { + fn from(code: u8) -> Self { + ExitCode(c::DWORD::from(code)) + } +} + fn zeroed_startupinfo() -> c::STARTUPINFO { c::STARTUPINFO { cb: 0, |
