Cargo.toml:
x
[dependencies]
anyhow = "1.0.55"
thiserror = "1.0.35"
src/main.rs:
xxxxxxxxxx
use thiserror::Error;
use anyhow;
pub enum MyError {
ErrorTypeOne(String),
ErrorTypeTwo {
reason: String,
},
}
fn main() {
let result = my_test_fn();
println!("error? {}", result.is_err());
if result.is_err() {
result.unwrap();
}
}
fn my_test_fn() -> anyhow::Result<i32> {
Err(MyError::ErrorTypeTwo { reason: "custom reason".to_string() }.into())
}