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

#478 in Operating systems

Download history 24137/week @ 2024-02-28 25773/week @ 2024-03-06 26898/week @ 2024-03-13 24277/week @ 2024-03-20 23739/week @ 2024-03-27 25923/week @ 2024-04-03 25624/week @ 2024-04-10 25805/week @ 2024-04-17 27779/week @ 2024-04-24 24542/week @ 2024-05-01 27339/week @ 2024-05-08 26532/week @ 2024-05-15 25625/week @ 2024-05-22 27230/week @ 2024-05-29 27451/week @ 2024-06-05 21322/week @ 2024-06-12

106,508 downloads per month
Used in 204 crates (171 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