Here is the code has been simplified since the original code is quite long:
fn main() {
let mut temp: Vec<&str> = Vec::new();
let arr = vec![
"1".to_string(),
"2".to_string(),
"3".to_string(),
"4".to_string(),
];
for ele in arr {
let test = ele;
let next_test = test.as_str();
temp.push(next_test);
}
println!("{:?}", temp);
}
And received:
error[E0597]: `test` does not live long enough
--> src/main.rs:11:25
|
11 | let next_test = test.as_str();
| ^^^^^^^^^^^^^ borrowed value does not live long enough
12 | temp.push(next_test);
| -------------------- borrow later used here
13 | }
| - `test` dropped here while still borrowed
Actually values in arr vector very complex, i want handle it in for loop and move them to temp vector, any one can help? Sorry about my English.