cmd_error 1.0.0

Simple crate to print an error message and exit while unwrapping Options and Results
Documentation
  • Coverage
  • 0%
    0 out of 6 items documented0 out of 3 items with examples
  • Size
  • Source code size: 14.54 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 196.26 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • AlexanderHarrison/cmd_error
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • AlexanderHarrison

When unwrapping Options and Results it's oddly annoying to print a simple error message and exit. This crate introduces the ErrExit trait which allows exactly that.

For example,

use cmd_error::ErrExit;

fn main() {
    let path = std::env::args().nth(1)
        .unwrap_exit("file path not passed");
    
    let file = std::fs::read_to_string(&path)
        .unwrap_exit(&format!("file {} not found", path));

    // ...
}

Why not use expect? Panic message aren't for users, they're for the programmers.

This crate also exports the function print_err_and_exit which unsurprisingly prints an error message and exits.

Exits with an exit code of 1. Errors are printed to stderr.