book
book copied to clipboard
C18.3 Reference destructuring is mentioned but not taught.
Related issue: https://github.com/rust-lang/book/issues/1539
I started writing a question on the "users" forum, but thought I might write an issue instead.
I am trying to sharpen my Rust knowledge a bit, so I am doing some freestyle code exploration around destructuring. I specifically wanted to learn more about reference destructuring and how to build valid code around it.
I am surprised to find that it seems to have been removed from the latest version of the book. It's mentioned but missing. Specifically in chapter 18.3, sub heading Destructuring to Break Apart Values:
We can also use patterns to destructure structs, enums, tuples, and references to use different parts of these values. Let’s walk through each value.
Below that is given examples for structs, enums, tuples, but not references!
Older versions of the book do contain the section, which I'm happy about.
https://github.com/rust-lang/book/issues/1539 says that the code has been removed since it was confusing, but maybe it might be good to add an up-to-date example?
So what's the "bug" in the book? I guess it should either say that reference destructuring is an advanced topic that isn't given as an example, or there should be examples for it?
Thanks for all your work on this excellent resource! ❤️
Came here to say that while reading the aforementioned chapter, I would have found it a bit helpful to simply see something like this in the section about deconstructing tuple structs:
struct Color(i32, i32, i32);
struct Point(i32, i32, i32);
let black = Color(0, 0, 0);
let origin = Point(0, 0, 0);
let Color(r, g, b) = black;
let Point(x, y, z) = origin;
While following the chapter and reading "tuple struct instances behave like tuples", I simply tried and failed with:
let (x, y, z) = origin;
Thank you for this great learning resource by the way!