Skip to content
Update rust error authored by umaumax's avatar umaumax
...@@ -206,4 +206,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { ...@@ -206,4 +206,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// hoge_sender.send_anyhow_result(hoge)?; // hoge_sender.send_anyhow_result(hoge)?;
Ok(()) Ok(())
} }
``` ```
\ No newline at end of file
## ライフタイムとエラー
エラーにライフタイム境界が含まれている場合に
`.map_err(|e| anyhow::anyhow!(e))?;`
とすると、`anyhow::Error`となり、型にはライフタイム境界が含まれていないが、
参照は残っているように見え、参照するライフタイムの影響が残る
`.map_err(|e| anyhow::anyhow!(e.to_string()))?;`とすることで、ライフタイムを参照しないエラーを返すことができる
\ No newline at end of file