cli-failure 1.0.0

Provides `Failure(String)` implementing `std::error::Error`. Includes convenience macros making it perfect for usage with `wrap-match` in CLIs.
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented1 out of 5 items with examples
  • Size
  • Source code size: 7.64 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.42 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • amsam0/cli-failure
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • naturecodevoid

cli-failure

Provides Failure(String) implementing std::error::Error. Includes convenience macros making it perfect for usage with wrap-match in CLIs.

This crate should not be used in libraries. Instead, use something like thiserror. For libraries, it is much better to have specific errors so library users can handle them better.

Documentation | crates.io

Example

// wrap-match is not required, but it is highly recommended
fn example() -> Result<(), Box<dyn Error>> {
    let result = "bad";
    // With convenience macros

    // These two lines are the same
    bail!("something {result} happened");
    return failure!("something {result} happened");

    return failure_raw!("something {result} happened").err_boxed();
    return Err(failure_raw!("something {result} happened").boxed());
    // Manually
    return Failure(format!("something {result} happened")).err_boxed();
    return Err(Failure(format!("something {result} happened")).boxed());
    Ok(())
}