1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-12-22 14:48:45 +02:00

Comprehensive Rust v2 (#1073)

I've taken some work by @fw-immunant and others on the new organization
of the course and condensed it into a form amenable to a text editor and
some computational analysis. You can see the inputs in `course.py` but
the interesting bits are the output: `outline.md` and `slides.md`.

The idea is to break the course into more, smaller segments with
exercises at the ends and breaks in between. So `outline.md` lists the
segments, their duration, and sums those durations up per-day. It shows
we're about an hour too long right now! There are more details of the
segments in `slides.md`, or you can see mostly the same stuff in
`course.py`.

This now contains all of the content from the v1 course, ensuring both
that we've covered everything and that we'll have somewhere to redirect
every page.

Fixes #1082.
Fixes #1465.

---------

Co-authored-by: Nicole LeGare <dlegare.1001@gmail.com>
Co-authored-by: Martin Geisler <mgeisler@google.com>
This commit is contained in:
Dustin J. Mitchell
2023-11-29 10:39:24 -05:00
committed by GitHub
parent ea204774b6
commit 6d19292f16
309 changed files with 6807 additions and 4281 deletions

View File

@@ -1,35 +1,3 @@
# Pattern Matching
The `match` keyword lets you match a value against one or more _patterns_. The
comparisons are done from top to bottom and the first match wins.
The patterns can be simple values, similarly to `switch` in C and C++:
```rust,editable
fn main() {
let input = 'x';
match input {
'q' => println!("Quitting"),
'a' | 's' | 'w' | 'd' => println!("Moving around"),
'0'..='9' => println!("Number input"),
_ => println!("Something else"),
}
}
```
The `_` pattern is a wildcard pattern which matches any value.
<details>
Key Points:
* You might point out how some specific characters are being used when in a pattern
* `|` as an `or`
* `..` can expand as much as it needs to be
* `1..=5` represents an inclusive range
* `_` is a wild card
* It can be useful to show how binding works, by for instance replacing a wildcard character with a variable, or removing the quotes around `q`.
* You can demonstrate matching on a reference.
* This might be a good time to bring up the concept of irrefutable patterns, as the term can show up in error messages.
</details>
{{%segment outline}}