diff options
| author | Luke Jones <luke.nukem.jones@gmail.com> | 2015-12-21 16:20:20 +1300 |
|---|---|---|
| committer | Luke Jones <luke.nukem.jones@gmail.com> | 2015-12-21 16:20:20 +1300 |
| commit | fc4bb5f77060b5822f25edbabbdf7a1d48a7f8fe (patch) | |
| tree | afc2b6f3f4549efc73c24a70d4f320f42bfe1d20 /src/doc | |
| parent | 981ac6d332ff19812532a4f64b6dc3f49114f75a (diff) | |
| download | rust-fc4bb5f77060b5822f25edbabbdf7a1d48a7f8fe.tar.gz rust-fc4bb5f77060b5822f25edbabbdf7a1d48a7f8fe.zip | |
Correct line wrap
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/book/match.md | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/doc/book/match.md b/src/doc/book/match.md index ce176e40b90..acffaf4544b 100644 --- a/src/doc/book/match.md +++ b/src/doc/book/match.md @@ -28,13 +28,19 @@ patterns][patterns] that covers all the patterns that are possible here. [patterns]: patterns.html -One of the many advantages of `match` is it enforces ‘exhaustiveness checking’. For example if we remove the last arm with the underscore `_`, the compiler will give us an error: +One of the many advantages of `match` is it enforces ‘exhaustiveness checking’. +For example if we remove the last arm with the underscore `_`, the compiler will +give us an error: ```text error: non-exhaustive patterns: `_` not covered ``` -Rust is telling us that we forgot a value. The compiler infers from `x` that it can have any positive 32bit value; for example 1 to 2,147,483,647. The `_` acts as a 'catch-all', and will catch all possible values that *aren't* specified in an arm of `match`. As you can see with the previous example, we provide `match` arms for integers 1-5, if `x` is 6 or any other value, then it is caught by `_`. +Rust is telling us that we forgot a value. The compiler infers from `x` that it +can have any positive 32bit value; for example 1 to 2,147,483,647. The `_` acts +as a 'catch-all', and will catch all possible values that *aren't* specified in +an arm of `match`. As you can see with the previous example, we provide `match` +arms for integers 1-5, if `x` is 6 or any other value, then it is caught by `_`. `match` is also an expression, which means we can use it on the right-hand side of a `let` binding or directly where an expression is used: @@ -52,7 +58,8 @@ let number = match x { }; ``` -Sometimes it’s a nice way of converting something from one type to another; in this example the integers are converted to `String`. +Sometimes it’s a nice way of converting something from one type to another; in +this example the integers are converted to `String`. # Matching on enums @@ -83,7 +90,8 @@ fn process_message(msg: Message) { Again, the Rust compiler checks exhaustiveness, so it demands that you have a match arm for every variant of the enum. If you leave one off, it -will give you a compile-time error unless you use `_` or provide all possible arms. +will give you a compile-time error unless you use `_` or provide all possible +arms. Unlike the previous uses of `match`, you can’t use the normal `if` statement to do this. You can use the [`if let`][if-let] statement, |
