0

In the current version of Rust (1.43) what exit code does a program produce if you return an Err from main()?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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!
@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 !.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.