You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/doc/book/match.md
+12-4
Original file line number
Diff line number
Diff line change
@@ -28,13 +28,19 @@ patterns][patterns] that covers all the patterns that are possible here.
28
28
29
29
[patterns]: patterns.html
30
30
31
-
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:
31
+
One of the many advantages of `match` is it enforces ‘exhaustiveness checking’.
32
+
For example if we remove the last arm with the underscore `_`, the compiler will
33
+
give us an error:
32
34
33
35
```text
34
36
error: non-exhaustive patterns: `_` not covered
35
37
```
36
38
37
-
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 `_`.
39
+
Rust is telling us that we forgot a value. The compiler infers from `x` that it
40
+
can have any positive 32bit value; for example 1 to 2,147,483,647. The `_` acts
41
+
as a 'catch-all', and will catch all possible values that *aren't* specified in
42
+
an arm of `match`. As you can see with the previous example, we provide `match`
43
+
arms for integers 1-5, if `x` is 6 or any other value, then it is caught by `_`.
38
44
39
45
`match` is also an expression, which means we can use it on the right-hand
40
46
side of a `let` binding or directly where an expression is used:
@@ -52,7 +58,8 @@ let number = match x {
52
58
};
53
59
```
54
60
55
-
Sometimes it’s a nice way of converting something from one type to another; in this example the integers are converted to `String`.
61
+
Sometimes it’s a nice way of converting something from one type to another; in
62
+
this example the integers are converted to `String`.
0 commit comments