'ref' is a counter-intuitive keyword

To add a bit to the conclusion in that thread, ref x as a binding mode has a nice property that *x as a pattern does not: both forms only make sense applied to identifiers, and not nested patterns, so picking the one analogous to mut avoids any questions around “materializing” new references.

Or in other words, the &x pattern matches against an actual structural part of an object- a pointer and its associated data. A hypothetical *x pattern doesn’t have anything to match against- it’s trying to add structure (a new pointer that doesn’t exist in the object) while other patterns remove it.

4 Likes