Open
Description
IIUC there is no good way to check whether a std::process::ExitCode
corresponds to success or failure. This is cumbersome, for example, when we want to check the exit code just before actually exiting.
use std::process::ExitCode;
fn real_main() -> ExitCode {
// ... do something ...
ExitCode::FAILED
}
fn main() -> ExitCode {
let exit_code = real_main();
// For now, the only way to check if `exit_code` is success is to check its
// Debug serialization:
if format!("{:?}", exit_code) != "ExitCode(unix_exit_status(0))" {
eprintln!("FAILED");
}
// Ideally we want to write this like:
/*
if !exit_code.is_success() {
eprintln!("FAILED!");
}
*/
exit_code
}
Can we add methods to std::process::ExitCode
checking whether it is success or failure?
It seems like is_success
/is_failure
were considered when stabilizing std::process::ExitCode
, but it was left as an unresolved question. #48711