Exit rust apps safely
std::process::exit warns:
"Note that because this function never returns, and that it terminates the process, no destructors on the current stack or any other thread’s stack will be run. If a clean shutdown is needed it is recommended to ... simply return a type implementing Termination ... from the main function and avoid this function altogether"
exit_safely provides a simple and highly transparent option to derive(Termination) from your own enum with a very simple API which still provides you full control over exit codes and what to (safely) output to stderr.
Minimal magic, maximum flexibilty, zero boilerplate.
Example
Here's the full example from the integration tests, showing how this plays really nicely with Try (derived via try_v2)
use Termination;
use *;
use io;
use Termination as _T; // Needed as trait bound for Exit
// Allows for simple `?` propogation of `io::Error`s
// And for validation of data you can impl From<foo> for Exit
// if given too few args it will fail with ExitCode 2 (InvocationError) and a message
// if given `<FILENAME> <FAIL>` it will fail with ExitCode (Other) 3,
// if given `<FILENAME> <ANYTHING_ELSE>` it will check file exists