book icon indicating copy to clipboard operation
book copied to clipboard

Need to talk about `ref` (bind by reference)

Open proski opened this issue 2 years ago • 3 comments
trafficstars

  • 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: https://github.com/rust-lang/book/commit/7f9a149b80c696d22fb77a74dd4fdc699d1b340d

Explore different ways of checking the error kind without consuming the error unnecessarily.

proski avatar Jul 31 '23 18:07 proski

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.

take-study avatar May 29 '24 13:05 take-study