derive-termination
Derive the std::process::Termination trait for an enum (annotate the variants with #[exit_code(n)]).
use ;
use Termination;
The Termination derive macro above expands to:
Every variant must carry an #[exit_code(N)] attribute; a missing attribute is a compile-time error that names the offending variant.
ExitCodeTable
Pair Termination with ExitCodeTable to get a static map from exit codes to variant names — useful for looking up a translation key, printing a reference table, or resolving an exit code back to a name.
use ;
exit_code_to_variant returns std::collections::BTreeMap<u8, &'static str>.
Changelog
2.0.0 (breaking)
- Missing
#[exit_code(N)]on a variant is now a hard error with a clear message (previously: silently skipped, which led to a confusingnon-exhaustive matchcompile error in generated code). - New
ExitCodeTablederive emittingfn exit_code_to_variant() -> BTreeMap<u8, &'static str>.
The std::process::Termination trait marks any type which is allowed to be returned from main.