cli-failure

Crates.iocli-failure
lib.rscli-failure
version1.0.0
created_at2023-08-03 07:03:45.50643+00
updated_at2023-08-03 07:03:45.50643+00
descriptionProvides `Failure(String)` implementing `std::error::Error`. Includes convenience macros making it perfect for usage with `wrap-match` in CLIs.
homepagehttps://github.com/naturecodevoid/cli-failure
repositoryhttps://github.com/naturecodevoid/cli-failure
max_upload_size
id933457
size7,959
(naturecodevoid)

documentation

https://docs.rs/cli-failure

README

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(())
}
Commit count: 5

cargo fmt