Add From for ExitCode · rust-lang/rust@cf4ac6b (original) (raw)
4 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1691,6 +1691,14 @@ impl ExitCode { | ||
1691 | 1691 | } |
1692 | 1692 | } |
1693 | 1693 | |
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 | + | |
1694 | 1702 | impl Child { |
1695 | 1703 | /// Forces the child process to exit. If the child has already exited, an [`InvalidInput`] |
1696 | 1704 | /// error is returned. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -476,6 +476,12 @@ impl ExitCode { | ||
476 | 476 | } |
477 | 477 | } |
478 | 478 | |
479 | +impl From<u8> for ExitCode { | |
480 | +fn from(code: u8) -> Self { | |
481 | +Self(code) | |
482 | +} | |
483 | +} | |
484 | + | |
479 | 485 | pub struct CommandArgs<'a> { |
480 | 486 | iter: crate::slice::Iter<'a, CString>, |
481 | 487 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -162,6 +162,15 @@ impl ExitCode { | ||
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
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 | + | |
165 | 174 | pub struct Process(!); |
166 | 175 | |
167 | 176 | impl Process { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -666,6 +666,12 @@ impl ExitCode { | ||
666 | 666 | } |
667 | 667 | } |
668 | 668 | |
669 | +impl From<u8> for ExitCode { | |
670 | +fn from(code: u8) -> Self { | |
671 | +ExitCode(c::DWORD::from(code)) | |
672 | +} | |
673 | +} | |
674 | + | |
669 | 675 | fn zeroed_startupinfo() -> c::STARTUPINFO { |
670 | 676 | c::STARTUPINFO { |
671 | 677 | cb: 0, |