I am new to Rust and I cannot solve this simple problem: Consider following code:
let mut a = vec![String::from("aa"), String::from("bb")];
a[0] += &*a[1];
Borrow checker rightfully complains about me having both immutable and mutable borrows here. It also suggests me:
help: try adding a local storing this...
--> src\main.rs:61:15
|
61 | a[0] += &*a[1];
| ^^^^
help: ...and then using that local here
--> src\main.rs:61:5
|
61 | a[0] += &*a[1];
| ^^^^^^^^^^^^^^
I do not really understand what that means. Do I really need to clone the string to perform such an easy operation? (That would result in 2 overall copies: into temporary and then back into a[0], instead of optimal 1 copy straight into a[0])