In types definitions, mut T doesn’t exist. Only &mut T
- ✅
&mut T - ❌
mut T
In variable bindings, mut is used like this:
let mut foo: T = ...
Note that mut in type and variable bindings serve a distinctly different role:
- Types:
&mut Tmeans we borrowTmutably - we are guaranteed exclusive mutable access.- Notice that
mut Tdoes not make sense in the first place, because we already control mutability via Ownership rules.
- Bindings:
let mutmeans the value can be mutated.- Allows lending to functions that accept
&mut Targuments
We can rebind T as mutable, but we cannot convert &T to &mut T. (implied by point 1 of Borrowing rules.)