Convert exit code to std::process::ExitCode On Windows, this supports the full u32 range including STATUS_CONTROL_C_EXIT (0xC000013A). On other platforms, only the lower 8 bits are used.
(code: u32)
| 9 | /// On Windows, this supports the full u32 range including STATUS_CONTROL_C_EXIT (0xC000013A). |
| 10 | /// On other platforms, only the lower 8 bits are used. |
| 11 | pub fn exit_code(code: u32) -> ExitCode { |
| 12 | #[cfg(windows)] |
| 13 | { |
| 14 | // For large exit codes like STATUS_CONTROL_C_EXIT (0xC000013A), |
| 15 | // we need to call std::process::exit() directly since ExitCode::from(u8) |
| 16 | // would truncate the value, and ExitCode::from_raw() is still unstable. |
| 17 | // FIXME: side effect in exit_code is not ideal. |
| 18 | if code > u8::MAX as u32 { |
| 19 | std::process::exit(code as i32) |
| 20 | } |
| 21 | } |
| 22 | ExitCode::from(code as u8) |
| 23 | } |
| 24 | |
| 25 | pub trait ErrorExt { |
| 26 | fn posix_errno(&self) -> i32; |