可変参照は特定のスコープで、ある特定のデータに対しては、 一つしか可変な参照を持てない
2022/2/17 22:44:00
fn main() {
let mut s = String::from("hello");
let r1 = &mut s;
let r2 = &mut s; //error
println!("{}, {}", r1, r2);
}
|
4 | let r1 = &mut s;
| ------ first mutable borrow occurs here
5 | let r2 = &mut s; //error
| ^^^^^^ second mutable borrow occurs here
6 |
7 | println!("{}, {}", r1, r2);
| -- first borrow later used here