-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch-all match arm variable used without explanation #1868
Comments
I agree! I understand this for the first time now that I have read your post! Definitely something which can be improved. |
I agree! I'm now reading Chapter 9.2 and find |
I agree, and is also find confusing this part: "The () is just the unit value, so nothing will happen in the _ case". The unit value was not properly explained before, and the sentence let me think that () work always (instead, it work for String but not for other types, such float) |
agree |
I didn't get it while reading chapter 9 either, and Google led me here. Agree. |
Interesting post. I was led here after I googled for 'rust other_error'. I was confused when reading chapter 9.2 just like you guys were. |
+1 google here |
Update books ## reference 1 commits in 4884fe45c14f8b22121760fb117181bb4da8dfe0..da6ea9b03f74cae0a292f40315723d7a3a973637 2021-07-28 21:31:28 -0700 to 2021-08-19 21:28:10 -0700 - Allow users to change status labels (rust-lang/reference#1083) ## book 7 commits in 7e49659102f0977d9142190e1ba23345c0f00eb1..687e21bde2ea10c261f79fa14797c5137425098d 2021-08-03 21:41:35 -0400 to 2021-08-18 20:48:38 -0400 - Small tweaks to Ferris size and position - Retain previous height: auto just in case - Shrink and move ferris when possible - Snapshot chapter 6 for nostarch - Demonstrate variable as catch-all for match. Fixes rust-lang/book#1868. - Improve the if let example to have a binding pattern. Fixes rust-lang/book#1401. - Fixes typo (rust-lang/book#2816) ## rust-by-example 1 commits in 0dc9cd4e89f00cb5230f120e1a083916386e422b..04f489c889235fe3b6dfe678ae5410d07deda958 2021-07-23 09:14:27 -0300 to 2021-08-17 08:01:20 -0300 - Grammar mistake (rust-lang/rust-by-example#1456) ## rustc-dev-guide 5 commits in c4644b4..cf0e151 2021-08-10 20:41:44 +0900 to 2021-08-22 11:47:02 -0300 - Fix typo “a Rc” → “an Rc” (rust-lang/rustc-dev-guide#1191) - Expand THIR section with more details (rust-lang/rustc-dev-guide#1183) - Remove docs for old -Z profile-queries flag - update mdbook version to latest - allow to quickly edit a page directly on github
Chapter 6.2, at the end, does discuss the
_
placeholder pattern. However it makes it sound super special, as opposed to just being an unused variable. No mention that you can use an arbitrary variable name to capture the value.Then in chapter 9.2 in listing 9-5 the catch-all is used again but with a named variable
other_error
.The only explanation given is The last arm of the outer match stays the same so the program panics on any error besides the missing file error. It claims that the last arm stays the same, but that arm pattern is
Err(error)
in the previous listing (9-4). So while the functionality might be the same, the match arm pattern definitely isn't.When I got to this as I was originally reading the book, this situation confused me. I was wondering if this is a special error matching generic or something. After some playing around with code I figured out you can just use arbitrary variables as the catch-all arm.
I think this situation could be greatly improved with just a minor note either in chapter 6.2 near the
_
placeholder pattern to say that you can actually capture the value and use it. Or a similar description near listing 9-5, instead of the claim that the last arm stays the same.The text was updated successfully, but these errors were encountered: