& Confusion again : Even The Book gets it wrong?

In my studies of The Book I arrived at chapter 18.3, "Destructuring References".

https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html#destructuring-references

It is stated here, that the & Operator is required in the definition of the closure, to prevent a compiler error. Confused again, I tried to omit the &, and (not really) surprise : the code works perfectly without it. (Tested in the Rust Playground)

I suspect, that the error producing compiler was an outdated version.

1 Like

&Point is correct. The Point syntax is now also accepted thanks to silent error correction that has been added as part of "match ergonomics":

https://github.com/rust-lang/rfcs/blob/master/text/2005-match-ergonomics.md

It looks like the book has been updated recently to reflect that:

https://doc.rust-lang.org/nightly/book/ch18-03-pattern-syntax.html#destructuring-references

3 Likes

Really great :+1:. I will continue my reading with the 'Nightly' version, of course.

Just to add to this, this particular feature is called "default match bindings" and introduced in the 2018 edition guide.

1 Like