Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Changes
Page history
Update rust error
authored
Dec 31, 2020
by
umaumax
Show whitespace changes
Inline
Side-by-side
rust/rust-error.md
View page @
e04ddd0d
...
...
@@ -29,3 +29,15 @@ file_result: Err(IO(Os { code: 21, kind: Other, message: "Is a directory" }))
```
`source`
属性を付加すると既存のエラーをラップして独自のエラーの中に情報を追加できる
[
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