From 6c7afa6227bab02b8b0e13e4237fa86ef541a52a Mon Sep 17 00:00:00 2001 From: daniel_yang Date: Tue, 3 Jun 2025 18:46:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=80=E5=A4=84=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E6=8F=8F=E8=BF=B0=E9=87=8D=E5=A4=8D=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch09-02-recoverable-errors-with-result.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index d232cbc..40d5f0a 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -220,7 +220,7 @@ hello.txt should be included in this project: Os { code: 2, kind: NotFound, mess 这个错误指出只能在返回 `Result`、`Option` 或者其它实现了 `FromResidual` 的类型的函数中使用 `?` 运算符。 -为了修复这个错误,有两个选择。一个是,如果没有限制的话将函数的返回值改为改为与你在 `?` 运算符所作用的值兼容的类型。另一个是使用 `match` 或者 `Result` 类型的方法,以适当的方式处理 `Result`。 +为了修复这个错误,有两个选择。一个是,如果没有限制的话将函数的返回值改为与你在 `?` 运算符所作用的值兼容的类型。另一个是使用 `match` 或者 `Result` 类型的方法,以适当的方式处理 `Result`。 错误信息也提到 `?` 也可用于 `Option` 值。如同对 `Result` 使用 `?` 一样,只能在返回 `Option` 的函数中对 `Option` 使用 `?`。在 `Option` 上调用 `?` 运算符的行为与 `Result` 类似:如果值是 `None`,此时 `None` 会从函数中提前返回。如果值是 `Some`,`Some` 中的值作为表达式的返回值同时函数继续。示例 9-11 中有一个从给定文本中返回第一行最后一个字符的函数的例子: