Crate quit[][src]

Expand description

This crate allows cleanly exiting a program using a custom exit code, without the drawbacks of process::exit. Destructors will be called as usual, and the stack will be unwound to the main function.

It is always required to attach #[main] to the main function. Then, with_code can be called from almost anywhere in the program. Restrictions are noted in the documentation for that function.

Implementation

Internally, this crate uses panicking to unwind the stack. Thus, if panicking is set to “abort” instead of the default “unwind”, setting the exit status will not work correctly. Changing this option may become an error in the future, if it can be detected at compile time.

Additionally, the program will not exit if with_code is called from a spawned thread, unless panics are propagated from that thread.

Examples

use std::env;

fn read_args() {
    if env::args_os().nth(1).is_some() {
        eprintln!("too many arguments");
        quit::with_code(1);
    }
}

#[quit::main]
fn main() {
    read_args();
}

Functions

Cleanly exits the program with an exit code.

Attribute Macros

Modifies the main function to exit with the code passed to with_code.