Skip to main content

ExitCode

Trait ExitCode 

Source
pub trait ExitCode: Sealed {
    // Provided method
    fn exit_code(&self) -> i32 { ... }
}
Expand description

Provide exit_code method for CliError. Intended to be passed to std::process::exit.

Provided Methods§

Source

fn exit_code(&self) -> i32

CLI application exit code

Examples found in repository?
examples/lazy_wrap.rs (line 24)
18fn main() {
19    let path = PathBuf::from("/not/an/exsisting/file");
20    let res = run(path);
21
22    if let Err(ref err) = res {
23        report::err_full(err);
24        std::process::exit(err.exit_code());
25    }
26}
More examples
Hide additional examples
examples/wrap_report_exit.rs (line 15)
8fn main() {
9    let res = config_error()
10        .wrap(CliError::Config)
11        .add_help("See https://docs.example.rs/config for more info");
12
13    if let Err(ref err) = res {
14        report::err_full(err);
15        std::process::exit(err.exit_code());
16    }
17}
examples/anyhow_report.rs (line 30)
22fn main() {
23    let res = inner_fn().context(CliError::OsErr);
24
25    if let Err(ref err) = res {
26        report::anyhow_err_full(err);
27        // As the error contains a `CliError`, this code will match its
28        // error_code. In this case `71`. If there was no underlying `CliError`,
29        // the code will default to `70`.
30        std::process::exit(err.exit_code());
31    }
32}

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ExitCode for Error

Available on crate feature anyhow only.
Source§

fn exit_code(&self) -> i32

Implementors§

Source§

impl ExitCode for CliError

Source§

impl ExitCode for narrate::Error

Available on crate feature error only.