Need help to make this work. I thought clone() would make a deep copy of my string. Then getting the literal-string of it would just be a value ... not linked to any variable?
fn main() {
let mut keep_vec: Vec<&str> = vec![];
let new_string = "New String".to_string();
// create a new string inside an expression
// and push it into the keep_vec
{
let second_string = "Second String".to_string();
/* created this after I got ERROR:
temporary value dropped while borrowed E0716
creates a temporary which is freed while still
in use Note: consider using a `let` binding to
create a longer lived value
*/
let string_clone = second_string.clone();
/* now getting this ERROR:
`string_clone` does not live long enough E0597
borrowed value does not live long enough
*/
keep_vec.push(string_clone.as_str());
}
keep_vec.push(&*new_string);
}
Here is a link to the Rust Playground.