Need to talk about `ref` (bind by reference)
proski opened this issue · comments
- I have searched open and closed issues and pull requests for duplicates, using these search terms:
- "ref"
- "bind by reference ref"
- I have checked the latest
main
branch to see if this has already been fixed, in this file:- rg --glob '*.md' '\bref\b'
URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html
Description of the problem:
The book doesn't mention the ref
keyword anywhere except the Appendix A. Earlier versions of the book had ref
in a few places, as evidenced by issues #947 and #950.
It's good that ref
doesn't appear in early parts of the book where it was an unnecessary complexity, the end result of those changes is that ref
is not described at all.
Suggested fix:
I believe it should be described in Chapter 18.3 next to the match guards. Maybe use an example from the old revision of Chapter 9.2: 7f9a149
Explore different ways of checking the error kind without consuming the error unnecessarily.
yes, when i read the match
part in ch6, i have no idea about the ownership, until i write some code in vscode the analyzer tell me that i can use ref
for borrow.