diff options
| author | bors <bors@rust-lang.org> | 2016-02-27 20:26:59 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-02-27 20:26:59 +0000 |
| commit | d56677a1878e9542f05e6468e0883574963c234d (patch) | |
| tree | fe4350fd886ac9255b7ece91447cd5dd9852d307 | |
| parent | d300e4f39b13b36b696fcff993b5b59969e4cec7 (diff) | |
| parent | edd5f3328b21e1fbaf1fbb861df678f2d0da2e53 (diff) | |
| download | rust-d56677a1878e9542f05e6468e0883574963c234d.tar.gz rust-d56677a1878e9542f05e6468e0883574963c234d.zip | |
Auto merge of #31931 - Luke-Nukem:master, r=steveklabnik
Refinement of paragraph referenced by [this issue](https://github.com/rust-lang/rust/issues/31927). The paragraph in question had been adjusted already, but I've made some further clarifications which should help with readability and not leave the reader any `dangling pointers`.
| -rw-r--r-- | src/doc/book/guessing-game.md | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/doc/book/guessing-game.md b/src/doc/book/guessing-game.md index 22b756f7bb4..b9b6e9a4c95 100644 --- a/src/doc/book/guessing-game.md +++ b/src/doc/book/guessing-game.md @@ -906,17 +906,17 @@ let guess: u32 = match guess.trim().parse() { Err(_) => continue, }; ``` - This is how you generally move from ‘crash on error’ to ‘actually handle the -error’, by switching from `expect()` to a `match` statement. The `Result` -returned by `parse()` is an `enum` like `Ordering`, but in this case, each -variant has some data associated with it: `Ok` is a success, and `Err` is a +error’, by switching from `expect()` to a `match` statement. A `Result` is +returned by `parse()`, this is an `enum` like `Ordering`, but in this case, +each variant has some data associated with it: `Ok` is a success, and `Err` is a failure. Each contains more information: the successfully parsed integer, or an -error type. In this case, we `match` on `Ok(num)`, which sets the inner value -of the `Ok` to the name `num`, and then we return it on the right-hand -side. In the `Err` case, we don’t care what kind of error it is, so we -use `_` instead of a name. This ignores the error, and `continue` causes us -to go to the next iteration of the `loop`. +error type. In this case, we `match` on `Ok(num)`, which sets the name `num` to +the unwrapped `Ok` value (ythe integer), and then we return it on the +right-hand side. In the `Err` case, we don’t care what kind of error it is, so +we just use the catch all `_` instead of a name. This catches everything that +isn't `Ok`, and `continue` lets us move to the next iteration of the loop; in +effect, this enables us to ignore all errors and continue with our program. Now we should be good! Let’s try: |
