When I using this code in Rust:
fn main() {
let s = String::from("hello").as_str();
println!("slice: {}", s);
}
the compiler shows error:
temporary value dropped while borrowed
creates a temporary value which is freed while still in userustcClick for full compiler diagnostic
main.rs(2, 43): temporary value is freed at the end of this statement
main.rs(3, 27): borrow later used here
main.rs(2, 5): consider using a `let` binding to create a longer lived value: `let binding = String::from("hello");
`, `binding`
does the as_str did not copy the value? I think the s
will live util the main function end. why still told that long live issue?