1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-01-20 21:18:26 +02:00

Update match-expressions.md (#367)

* Update match-expressions.md

* Apply suggestions from code review

Fine tuning the casing and explanations.

---------

Co-authored-by: Martin Geisler <mgeisler@google.com>
This commit is contained in:
Charisee Chiw 2023-02-09 13:16:30 -08:00 committed by GitHub
parent 36ce63cb10
commit 65340c4ca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,3 +21,12 @@ expression of the block, if any. In the example above, the type is `()`.
See [pattern matching](../pattern-matching.md) for more details on patterns in
Rust.
<details>
* Save the match expression to a variable and print it out.
* Remove `.as_deref()` and explain the error.
* `std::env::Agrs().next` returns an `Option<&String>`, but we cannot match against `String`.
* `as_deref()` transforms an `Option<T>` to `Option<T::Target>`. In our case, this turns `Option<&String>` into `Option<&str>`.
* We can now use pattern matching to match against the `&str` inside `Option`.
</details>