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..42a1ff730e379 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 c6f641d0932bf..7bfcac8de1715 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,