From 7f9a149b80c696d22fb77a74dd4fdc699d1b340d Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Wed, 28 Dec 2016 20:25:34 -0500 Subject: [PATCH] Explain ref --- src/ch09-02-recoverable-errors-with-result.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index f0e6abb..8bf5b2b 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -236,10 +236,11 @@ The condition `if error.kind() == ErrorKind::NotFound` is called a *match guard*: it's an extra condition on a `match` arm that further refines the arm's pattern. This condition must be true in order for that arm's code to get run; otherwise, the pattern matching will move on to consider the next arm in the -`match`. The `ref` in the pattern is needed so that the `error` is -not moved into the guard condition but is merely referenced by it. - - +`match`. The `ref` in the pattern is needed so that the `error` is not moved +into the guard condition but is merely referenced by it. The reason `ref` is +used to take a reference in a pattern instead of `&` will be covered in detail +in Chapter XX. In short, in the context of a pattern, `&` matches a reference +and give us its value, but `ref` matches a value and gives us a reference to it. The condition we want to check in the match guard is whether the value returned by `error.kind()` is the `NotFound` variant of the `ErrorKind` enum. If it is,