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 03, 2021
by
umaumax
Hide whitespace changes
Inline
Side-by-side
rust/rust-error.md
View page @
a6cf289d
...
...
@@ -59,7 +59,7 @@ extern crate anyhow;
サーベイはこちら
[
Error Handling Survey
](
https://blog.yoshuawuyts.com/error-handling-survey/
)
##
#
thiserror
## thiserror
```
rust
use
std
::
fs
::
File
;
...
...
@@ -101,7 +101,7 @@ pub enum MyError {
}
```
###
#
`anyhow::Error`から`thiserror`への移行方法
### `anyhow::Error`から`thiserror`への移行方法
方針
*
`anyhow::Result`
や
`Box<dyn std::error::Error>`
を
`pub type Result<T, E = MyError> = std::result::Result<T, E>;`
へ置き換える
*
既存のエラー型を受け入れられる
`thiserror`
のエラー型を
`Anyhow(#[from] anyhow::Error)`
のようにして作成する
...
...
...
...