From cf4ac6b1e16e08ee7513ed03a323c6d00504beb2 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Fri, 28 Jan 2022 14:07:27 -0800 Subject: [PATCH 1/2] Add From for ExitCode This should cover a mostly cross-platform subset of supported exit codes. --- library/std/src/process.rs | 8 ++++++++ library/std/src/sys/unix/process/process_common.rs | 6 ++++++ library/std/src/sys/unsupported/process.rs | 9 +++++++++ library/std/src/sys/windows/process.rs | 6 ++++++ 4 files changed, 29 insertions(+) diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 7d7e08a714938..1f04890539604 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1691,6 +1691,14 @@ impl ExitCode { } } +#[unstable(feature = "process_exitcode_placeholder", issue = "48711")] +impl From for ExitCode { + /// Construct an exit code from an arbitrary u8 value. + fn from(code: u8) -> Self { + ExitCode(imp::ExitCode::from(code)) + } +} + impl Child { /// Forces the child process to exit. If the child has already exited, an [`InvalidInput`] /// error is returned. diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 7ac2f9d8af75a..97985ddd3316b 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 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 7846e43cfb53e..deb58ffa8c7de 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 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 5ad570427978e..f9e71951b2a23 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 for ExitCode { + fn from(code: u8) -> Self { + ExitCode(c::DWORD::from(code)) + } +} + fn zeroed_startupinfo() -> c::STARTUPINFO { c::STARTUPINFO { cb: 0, From 4c5a36e2d1ac0c5d86ba0a75426d601e7c9202b0 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Mon, 7 Feb 2022 12:45:36 -0800 Subject: [PATCH 2/2] fix exclusive range error --- library/std/src/sys/unsupported/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/unsupported/process.rs b/library/std/src/sys/unsupported/process.rs index deb58ffa8c7de..42a1ff730e379 100644 --- a/library/std/src/sys/unsupported/process.rs +++ b/library/std/src/sys/unsupported/process.rs @@ -166,7 +166,7 @@ impl From for ExitCode { fn from(code: u8) -> Self { match code { 0 => Self::SUCCESS, - 1..255 => Self::FAILURE, + 1..=255 => Self::FAILURE, } } }