Skip to content

Commit 981ac6d

Browse files
author
Luke Jones
committed
Rewrite paragraph in 'match' to be more concise and readable. Start
correcting use of ':' in sentences. The colon `:` should be used only when the sentence preceeding it is a complete sentence. If this is not the case, then a `;` should be used; this denotes that the following fragment is a part of the previous fragment.
1 parent 33914f2 commit 981ac6d

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

src/doc/book/documentation.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ document your project.
99
The Rust distribution includes a tool, `rustdoc`, that generates documentation.
1010
`rustdoc` is also used by Cargo through `cargo doc`.
1111

12-
Documentation can be generated in two ways: from source code, and from
12+
Documentation can be generated in two ways; from source code, and from
1313
standalone Markdown files.
1414

1515
## Documenting source code
@@ -73,7 +73,7 @@ hello.rs:4 }
7373
```
7474

7575
This [unfortunate error](https://github.com/rust-lang/rust/issues/22547) is
76-
correct: documentation comments apply to the thing after them, and there's
76+
correct; documentation comments apply to the thing after them, and there's
7777
nothing after that last comment.
7878

7979
[rc-new]: https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.new
@@ -385,7 +385,7 @@ error handling. Lets say you want the following,
385385

386386
```rust,ignore
387387
/// use std::io;
388-
/// let mut input = String::new();
388+
/// let mut input = String::new();
389389
/// try!(io::stdin().read_line(&mut input));
390390
```
391391

@@ -398,7 +398,7 @@ don't return anything so this will give a mismatched types error.
398398
/// ```
399399
/// use std::io;
400400
/// # fn foo() -> io::Result<()> {
401-
/// let mut input = String::new();
401+
/// let mut input = String::new();
402402
/// try!(io::stdin().read_line(&mut input));
403403
/// # Ok(())
404404
/// # }

src/doc/book/match.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,18 @@ match x {
2323
`match` takes an expression and then branches based on its value. Each ‘arm’ of
2424
the branch is of the form `val => expression`. When the value matches, that arm’s
2525
expression will be evaluated. It’s called `match` because of the term ‘pattern
26-
matching’, which `match` is an implementation of. There’s an [entire section on
26+
matching’, which `match` is an implementation of. There’s a [separate section on
2727
patterns][patterns] that covers all the patterns that are possible here.
2828

2929
[patterns]: patterns.html
3030

31-
So what’s the big advantage? Well, there are a few. First of all, `match`
32-
enforces ‘exhaustiveness checking’. Do you see that last arm, the one with the
33-
underscore (`_`)? If we remove that arm, Rust will give us an error:
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:
3432

3533
```text
3634
error: non-exhaustive patterns: `_` not covered
3735
```
3836

39-
In other words, Rust is trying to tell us we forgot a value. Because `x` is an
40-
integer, Rust knows that it can have a number of different values – for
41-
example, `6`. Without the `_`, however, there is no arm that could match, and
42-
so Rust refuses to compile the code. `_` acts like a ‘catch-all arm’. If none
43-
of the other arms match, the arm with `_` will, and since we have this
44-
catch-all arm, we now have an arm for every possible value of `x`, and so our
45-
program will compile successfully.
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 `_`.
4638

4739
`match` is also an expression, which means we can use it on the right-hand
4840
side of a `let` binding or directly where an expression is used:
@@ -60,7 +52,7 @@ let number = match x {
6052
};
6153
```
6254

63-
Sometimes it’s a nice way of converting something from one type to another.
55+
Sometimes it’s a nice way of converting something from one type to another; in this example the integers are converted to `String`.
6456

6557
# Matching on enums
6658

@@ -91,7 +83,7 @@ fn process_message(msg: Message) {
9183

9284
Again, the Rust compiler checks exhaustiveness, so it demands that you
9385
have a match arm for every variant of the enum. If you leave one off, it
94-
will give you a compile-time error unless you use `_`.
86+
will give you a compile-time error unless you use `_` or provide all possible arms.
9587

9688
Unlike the previous uses of `match`, you can’t use the normal `if`
9789
statement to do this. You can use the [`if let`][if-let] statement,

src/doc/book/patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on a whirlwind tour of all of the things patterns can do!
77
[bindings]: variable-bindings.html
88
[match]: match.html
99

10-
A quick refresher: you can match against literals directly, and `_` acts as an
10+
A quick refresher; you can match against literals directly, and `_` acts as an
1111
‘any’ case:
1212

1313
```rust

0 commit comments

Comments
 (0)