I have the following simple code. I am not able to figure out how to resolve the error "borrowed value does not live long enough".
fn main() {
let mut saved_message: Vec<&str> = Vec::new();
for i in 0..10 {
let mut tmp: String = String::from("line_num ");
tmp.push_str(&i.to_string());
saved_message.push(&tmp);
}
}
Compiling rust_test v0.1.0 (C:\workspace\rust_test)
error[E0597]: `tmp` does not live long enough
--> src\lib.rs:6:28
|
6 | saved_message.push(&tmp);
| -------------------^^^^-
| | |
| | borrowed value does not live long enough
| borrow later used here
7 | }
| - `tmp` dropped here while still borrowed
For more information about this error, try `rustc --explain E0597`.
error: could not compile `rust_test` due to previous error