DEV Community

Zhangwuji
Zhangwuji

Posted on

Rust control and for in

let  mut hh=Person {
        name:String::from("jack")
};

 let  a = vec![ hh];
 a[0].name=String::from("jack");
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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;

  1. & mut a; and mut a

Top comments (0)