Might be worth noting that "dropped" in this context doesn't necessarily correspond to the reference going out of scope:
fn get_first(v: &Vec<i32>) -> &i32 { &v[0] } fn main() { let mut v = vec![0, 1, 2]; let first = get_first(&v); print!("{}", first}); v.push(3); // Works! // print!("{}", first); // Doesn't work }
This item has no comments currently.
It looks like you have JavaScript disabled. This web app requires that JavaScript is enabled.
Please enable JavaScript to use this site (or just go read Hacker News).
Might be worth noting that "dropped" in this context doesn't necessarily correspond to the reference going out of scope: