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

#527 in Operating systems

Download history 24788/week @ 2024-08-21 27322/week @ 2024-08-28 30791/week @ 2024-09-04 28444/week @ 2024-09-11 26073/week @ 2024-09-18 30580/week @ 2024-09-25 25756/week @ 2024-10-02 26603/week @ 2024-10-09 28336/week @ 2024-10-16 28235/week @ 2024-10-23 26657/week @ 2024-10-30 25768/week @ 2024-11-06 27702/week @ 2024-11-13 26863/week @ 2024-11-20 21604/week @ 2024-11-27 21144/week @ 2024-12-04

102,342 downloads per month
Used in 223 crates (187 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