feat: add thiserror anyhow

This commit is contained in:
2021-02-09 23:22:46 +08:00
parent 6f36859a4e
commit 03c5919538
4 changed files with 102 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
use thiserror::Error;
use anyhow::{Context, Result};
#[derive(Error, Debug)]
pub enum SimpleError {
#[error("error status")]
ErrorStatus(u32),
#[error("unknown error")]
Unknown,
}
fn main() {
do_something().unwrap();
}
fn do_something() -> Result<String, Box<dyn std::error::Error>> {
Err(Box::new(SimpleError::Unknown)).with_context(|| format!("Error unknown!"))?
}