From 585ca61bc836994a28695bad841a264e4d328ab3 Mon Sep 17 00:00:00 2001 From: spike <86768220+yaoming00@users.noreply.github.com> Date: Wed, 23 Feb 2022 11:51:33 +0800 Subject: [PATCH 1/2] Update result.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 参考自: https://stackoverflow.com/questions/61301581/when-should-we-use-unwrap-vs-expect-in-rust --- contents/basic/result-error/result.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/basic/result-error/result.md b/contents/basic/result-error/result.md index c578830b..fabd9cfa 100644 --- a/contents/basic/result-error/result.md +++ b/contents/basic/result-error/result.md @@ -119,7 +119,7 @@ thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { cod note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` -`expect` 跟 `unwrap` 很像,只不过它允许指定 `panic!` 时的报错信息: +`expect` 跟 `unwrap` 很像,也是遇到错误直接 panic, 但是会带上自定义的错误提示信息,相当于重载了错误打印的函数: ```rust use std::fs::File; From 079022659c0e3bc0aa290b4a8a9c3d36c88f0e6e Mon Sep 17 00:00:00 2001 From: spike <86768220+yaoming00@users.noreply.github.com> Date: Wed, 23 Feb 2022 11:52:25 +0800 Subject: [PATCH 2/2] Update result.md --- contents/basic/result-error/result.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/basic/result-error/result.md b/contents/basic/result-error/result.md index fabd9cfa..640fe03b 100644 --- a/contents/basic/result-error/result.md +++ b/contents/basic/result-error/result.md @@ -119,7 +119,7 @@ thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { cod note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` -`expect` 跟 `unwrap` 很像,也是遇到错误直接 panic, 但是会带上自定义的错误提示信息,相当于重载了错误打印的函数: +`expect` 跟 `unwrap` 很像,也是遇到错误直接 `panic`, 但是会带上自定义的错误提示信息,相当于重载了错误打印的函数: ```rust use std::fs::File;