Я хочу сохранить значение в VecDeque, а затем обновить его.
Минимальный пример:
use std::collections::VecDeque;
fn main() {
let mut v = VecDeque::new();
let mut str1 = String::from("Hello");
v.push_back(str1);
let str = String::from(" World");
str1.push_str(&str);
}
Ошибка:
Compiling playground v0.0.1 (/playground)
error[E0382]: borrow of moved value: `str1`
--> src/main.rs:10:5
|
5 | let mut str1 = String::from("Hello");
| -------- move occurs because `str1` has type `std::string::String`, which does not implement the `Copy` trait
6 |
7 | v.push_back(str1);
| ---- value moved here
...
10 | str1.push_str(&str);
| ^^^^ value borrowed here after move
error: aborting due to previous error
Вопрос:
Как я могу добавить элемент в коллекцию и после этого обновить этот элемент?