let mut hh=Person {
name:String::from("jack")
};
let a = vec![ hh];
a[0].name=String::from("jack");
the element inner vec's control is managed by vec instance;
So even though hh variable is mutable,but it is not useful.
a variable is mutable or immutable that really work;
let mut a = vec![ hh];
let refrenceA=&a
refrenceA variable's type is a immutable reference;
No matter a variable is mutable or immutable, Only it' refrence like&a
is default setted up to mutable refrence. if want to become mutable refrence;
- & mut a; and mut a
Top comments (0)