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
Oct 18, 2021
by
umaumax
Show whitespace changes
Inline
Side-by-side
rust/rust-error.md
View page @
b7c62185
...
...
@@ -207,3 +207,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok
(())
}
```
## ライフタイムとエラー
エラーにライフタイム境界が含まれている場合に
`.map_err(|e| anyhow::anyhow!(e))?;`
とすると、
`anyhow::Error`
となり、型にはライフタイム境界が含まれていないが、
参照は残っているように見え、参照するライフタイムの影響が残る
`.map_err(|e| anyhow::anyhow!(e.to_string()))?;`
とすることで、ライフタイムを参照しないエラーを返すことができる
\ No newline at end of file