Add From<u8> for ExitCode

This should cover a mostly cross-platform subset of supported exit codes.
This commit is contained in:
Jane Lusby 2022-01-28 14:07:27 -08:00 committed by David Tolnay
parent f624427f87
commit cf4ac6b1e1
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
4 changed files with 29 additions and 0 deletions

View File

@ -1691,6 +1691,14 @@ impl ExitCode {
}
}
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
impl From<u8> 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.

View File

@ -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>,
}

View File

@ -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 {

View File

@ -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,