Skip to content

Commit cf4ac6b

Browse files
yaahcdtolnay
authored andcommitted
Add From<u8> for ExitCode
This should cover a mostly cross-platform subset of supported exit codes.
1 parent f624427 commit cf4ac6b

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

library/std/src/process.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,14 @@ impl ExitCode {
16911691
}
16921692
}
16931693

1694+
#[unstable(feature = "process_exitcode_placeholder", issue = "48711")]
1695+
impl From<u8> for ExitCode {
1696+
/// Construct an exit code from an arbitrary u8 value.
1697+
fn from(code: u8) -> Self {
1698+
ExitCode(imp::ExitCode::from(code))
1699+
}
1700+
}
1701+
16941702
impl Child {
16951703
/// Forces the child process to exit. If the child has already exited, an [`InvalidInput`]
16961704
/// error is returned.

library/std/src/sys/unix/process/process_common.rs

+6
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,12 @@ impl ExitCode {
476476
}
477477
}
478478

479+
impl From<u8> for ExitCode {
480+
fn from(code: u8) -> Self {
481+
Self(code)
482+
}
483+
}
484+
479485
pub struct CommandArgs<'a> {
480486
iter: crate::slice::Iter<'a, CString>,
481487
}

library/std/src/sys/unsupported/process.rs

+9
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ impl ExitCode {
162162
}
163163
}
164164

165+
impl From<u8> for ExitCode {
166+
fn from(code: u8) -> Self {
167+
match code {
168+
0 => Self::SUCCESS,
169+
1..255 => Self::FAILURE,
170+
}
171+
}
172+
}
173+
165174
pub struct Process(!);
166175

167176
impl Process {

library/std/src/sys/windows/process.rs

+6
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,12 @@ impl ExitCode {
666666
}
667667
}
668668

669+
impl From<u8> for ExitCode {
670+
fn from(code: u8) -> Self {
671+
ExitCode(c::DWORD::from(code))
672+
}
673+
}
674+
669675
fn zeroed_startupinfo() -> c::STARTUPINFO {
670676
c::STARTUPINFO {
671677
cb: 0,

0 commit comments

Comments
 (0)