Skip to content
Update rust error authored by umaumax's avatar umaumax
......@@ -101,6 +101,27 @@ pub enum MyError {
}
```
### thiserrorでよくあるクレートのエラー型の自動変換用の定義例
``` rust
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
IO(#[from] std::io::Error),
#[error(transparent)]
Anyhow(#[from] anyhow::Error),
#[error(transparent)]
SerdeYaml(#[from] serde_yaml::Error),
#[error(transparent)]
SerdeJson(#[from] serde_json::Error),
#[error(transparent)]
Image(#[from] image::ImageError),
#[error(transparent)]
CSV(#[from] csv::Error),
}
```
### `anyhow::Error`から`thiserror`への移行方法
方針
* `anyhow::Result``Box<dyn std::error::Error>``pub type Result<T, E = MyError> = std::result::Result<T, E>;`へ置き換える
......
......