Names used for reference types in the community

So, after reading some other posts, articles, and tutorials mainly about these types: (1) &T, (2) &mut T, (3) mut & T, and (4) mut &mut T. I am a bit confused about the naming, especially for the first two.
Most if not all resources use the term "immutable reference" and "mutable reference" for the first and the second respectively. Now from my understanding of the English language (I'm not a native speaker) the correct terms would be more along the following:
(1): "immutable reference" (implying immutability of T)
(2): "immutable reference to mutable value"
(3): "mutable reference" (actually being able tu mutate the reference itself, again implying immutability of T)
(4): "mutable reference to mutable value"

When always assuming immutability, (1) and (2) could also be shortened by dropping the "immutable" parts.

Now my guess would be either, the naming has historically grown to be what it is ("mutable reference" is obviously more ergonomic than "immutable reference to mutable value" given that (2) is much more common than (3), but from my understanding the first is just wrong for what it is used), or my understanding of the language is wrong?

I'm not proposing that we should change any text's out there, but just for the sake of my understanding :wink:
Thanks in advance

The first mut in mut &T and mut &mut T is not part of the type. It's a property of the variable binding: can its value be changed.

let mut x: &u32 = ...;

The thing above defines a new variable x. It contains values of type "immutable reference to u32", however the variable itself can be mutated.

You may also like this article.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.