In the current version of Rust (1.43) what exit code does a program produce if you return an Err from main()?
1 Answer
The Termination trait is used to get an exit code from whatever main returns. The existing implementations wrap libc's EXIT_SUCCESS or EXIT_FAILURE which... are implementation-defined. But on unix-like systems they're probably 0 and 1.
2 Comments
Timmmm
Ah I did find that but figured it wasn't available yet since
anyhow::Result doesn't implement it. But seems like there is a default implementation which returns EXIT_SUCCESS/EXIT_FAILURE. Thanks!Masklinn
@Timmmm there's an implenentation of Termination specifically for
Result<(), E> and Result<!, E> in the stdlib. Since anyhow::Result is just a typedef for Result<T, anyhow::Error> it inherits these implementations as long as T is either () or !.