Rust control and for in

zhangwuji

Zhangwuji

Posted on May 21, 2024

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
💖 💪 🙅 🚩
zhangwuji
Zhangwuji

Posted on May 21, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related