Skip to content
Update rust error authored by umaumax's avatar umaumax
...@@ -28,4 +28,16 @@ err: Hoge ...@@ -28,4 +28,16 @@ err: Hoge
file_result: Err(IO(Os { code: 21, kind: Other, message: "Is a directory" })) file_result: Err(IO(Os { code: 21, kind: Other, message: "Is a directory" }))
``` ```
`source`属性を付加すると既存のエラーをラップして独自のエラーの中に情報を追加できる `source`属性を付加すると既存のエラーをラップして独自のエラーの中に情報を追加できる
\ No newline at end of file
[dtolnay/thiserror: derive\(Error\) for struct and enum error types]( https://github.com/dtolnay/thiserror )
``` rs
#[derive(Error, Debug)]
pub enum MyError {
...
#[error(transparent)]
Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error
}
```
\ No newline at end of file