From ef2a0eaa6acd41162a56d7057e7bb3349ab1b732 Mon Sep 17 00:00:00 2001 From: Tom Godkin Date: Sat, 9 Mar 2019 11:41:08 +0000 Subject: [PATCH] ch09-02: ? may be used with Result or Option --- src/ch09-02-recoverable-errors-with-result.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 80d07b3276..04be291eb2 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -470,13 +470,13 @@ and returns it. Of course, using `fs::read_to_string` doesn’t give us the opportunity to explain all the error handling, so we did it the longer way first. -#### The `?` Operator Can Only Be Used in Functions That Return `Result` +#### The `?` Operator Can Only Be Used in Functions That Return `Result` or `Option` The `?` operator can only be used in functions that have a return type of -`Result`, because it is defined to work in the same way as the `match` -expression we defined in Listing 9-6. The part of the `match` that requires a -return type of `Result` is `return Err(e)`, so the return type of the function -must be a `Result` to be compatible with this `return`. +`Result` or `Option`, because it is defined to work in the same way as the +`match` expression we defined in Listing 9-6. The part of the `match` that +requires a return type of `Result` is `return Err(e)`, so the return type of +the function must be a `Result` to be compatible with this `return`. Let’s look at what happens if we use the `?` operator in the `main` function, which you’ll recall has a return type of `()`: