You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-12-21 14:35:47 +02:00
docs: improve language in pattern-matching section (#2879)
I asked Gemini to review the English for inconsistencies and grammar mistakes. This is the result and I hope it's useful! As a non-native speaker, it is hard for me to evaluate the finer details, so let me know if you would like to see changes (or even better: make them directly in the PR with the suggestion function). --------- Co-authored-by: Dmitri Gribenko <gribozavr@gmail.com>
This commit is contained in:
@@ -4,7 +4,7 @@ minutes: 4
|
|||||||
|
|
||||||
# Structs
|
# Structs
|
||||||
|
|
||||||
Like tuples, Struct can also be destructured by matching:
|
Like tuples, structs can also be destructured by matching:
|
||||||
|
|
||||||
```rust,editable
|
```rust,editable
|
||||||
{{#include ../../third_party/rust-by-example/destructuring-structs.rs}}
|
{{#include ../../third_party/rust-by-example/destructuring-structs.rs}}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ to `30`. We can represent the expression as a tree:
|
|||||||
```
|
```
|
||||||
|
|
||||||
A bigger and more complex expression would be `(10 * 9) + ((3 - 4) * 5)`, which
|
A bigger and more complex expression would be `(10 * 9) + ((3 - 4) * 5)`, which
|
||||||
evaluate to `85`. We represent this as a much bigger tree:
|
evaluates to `85`. We represent this as a much bigger tree:
|
||||||
|
|
||||||
<!-- mdbook-xgettext: skip -->
|
<!-- mdbook-xgettext: skip -->
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ fn main() {
|
|||||||
- Patterns are type-specific, including irrefutable patterns. Try adding or
|
- Patterns are type-specific, including irrefutable patterns. Try adding or
|
||||||
removing an element to the tuple and look at the resulting compiler errors.
|
removing an element to the tuple and look at the resulting compiler errors.
|
||||||
|
|
||||||
- Variable names are patterns that always match and which bind the matched value
|
- Variable names are patterns that always match and bind the matched value into
|
||||||
into a new variable with that name.
|
a new variable with that name.
|
||||||
|
|
||||||
- `_` is a pattern that always matches any value, discarding the matched value.
|
- `_` is a pattern that always matches any value, discarding the matched value.
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ minutes: 10
|
|||||||
|
|
||||||
# Let Control Flow
|
# Let Control Flow
|
||||||
|
|
||||||
Rust has a few control flow constructs which differ from other languages. They
|
Rust has a few control flow constructs that differ from other languages. They
|
||||||
are used for pattern matching:
|
are used for pattern matching:
|
||||||
|
|
||||||
- `if let` expressions
|
- `if let` expressions
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Like with `if let`, there is a
|
Like with `if let`, there is a
|
||||||
[`while let`](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops)
|
[`while let`](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops)
|
||||||
variant which repeatedly tests a value against a pattern:
|
variant that repeatedly tests a value against a pattern:
|
||||||
|
|
||||||
```rust,editable
|
```rust,editable
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ Key Points:
|
|||||||
- You might point out how some specific characters are being used when in a
|
- You might point out how some specific characters are being used when in a
|
||||||
pattern
|
pattern
|
||||||
- `|` as an `or`
|
- `|` as an `or`
|
||||||
- `..` can expand as much as it needs to be
|
- `..` matches any number of items
|
||||||
- `1..=5` represents an inclusive range
|
- `1..=5` represents an inclusive range
|
||||||
- `_` is a wild card
|
- `_` is a wild card
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user