#sysexits #exitcode

exitcode

Preferred system exit codes as defined by sysexits.h

5 stable releases

Uses old Rust 2015

1.1.2 Jun 18, 2017
1.1.1 Jun 11, 2017
1.0.1 May 27, 2017
1.0.0 May 25, 2017

#26 in Operating systems

Download history 6057/week @ 2020-06-19 3958/week @ 2020-06-26 6695/week @ 2020-07-03 9006/week @ 2020-07-10 6968/week @ 2020-07-17 6711/week @ 2020-07-24 13967/week @ 2020-07-31 4601/week @ 2020-08-07 5075/week @ 2020-08-14 5907/week @ 2020-08-21 5971/week @ 2020-08-28 5960/week @ 2020-09-04 6960/week @ 2020-09-11 6744/week @ 2020-09-18 7476/week @ 2020-09-25 4897/week @ 2020-10-02

28,945 downloads per month
Used in 41 crates (39 directly)

Apache-2.0

7KB

ghit.me Build Status Crates.io

exitcode

System exit code constants as defined by sysexits.h

Documentation is available here

Installing from crates.io

[dependencies]
exitcode = "1.1.2"

Example

extern crate exitcode;

use std::process;

pub fn parse_int_or_return_error_exitcode(s: String) -> Result<i32, exitcode::ExitCode> {
    match s.parse::<i32>() {
        Ok(i) => Ok(i),
        Err(_) => Err(exitcode::USAGE)
    }

}

pub fn main() {

    match parse_int_or_return_error_exitcode("123".to_string()) {
        Ok(i) => println!("Parsed: {}", i),
        Err(code) => {
            println!("Parse error.  Exiting with code: {}", code);
            process::exit(code);
        }
    }

    match parse_int_or_return_error_exitcode("foo".to_string()) {
        Ok(i) => println!("Parsed: {}", i),
        Err(code) => {
            println!("Parse error.  Exiting with code: {}", code);
            process::exit(code);
        }
    }

    println!("Exiting with code: {}", exitcode::OK);
    process::exit(exitcode::OK);

}

No runtime deps