by Peaker · 12y ago · 0 comments
let x = 5
let mut y = &x
If I understood correctly, x is immutable, but can still be mutated via (*y)?I believe it actually means that y can be made to reference something other than x.
let x = 5
let mut y = &x
let i = 13
y = &i
This is similar to C++'s const-pointers and pointers-to-consts, where either a pointer cannot be made to point at something different or the pointer cannot be used to change what it points at. let y = &mut x;
which will result in an error due to x not being mutable.