My apologies if this has been asked elsewhere. This is a very simple question but I have yet to find an answer to. Consider this:
let &mut x = &mut "hello";
The compiler tells me that x
is of type &str
. I was expecting it to be a &mut &mut &str
type or a &mut &str
type. Did the compiler cancel out the &mut
from both side? This was a surprise to me. Similarity, this x
also ends up being a &str
type:
let x = &mut "hello";
let &mut x = x;
I thought maybe the compiler don't allow &mut &mut <type>
types but this is not true, the following works:
let mut x = &mut "hello";
let x = &mut x;
I'm somewhat confused by the placement of &mut
between the left and right side.