Rust control and for in
Zhangwuji
Posted on May 21, 2024
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
💖 💪 🙅 🚩
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.