Compiling the following snippet:
use std::env;
fn main() {
let base = env::home_dir()
.map(|p| p.join(".foo"))
.map(|p| p.join("bar"))
.map(|p| p.display())
.expect("dir not loadable");
println!("Name: {}", base)
}
I get the error:
error[E0597]: `p` does not live long enough
--> src/main.rs:7:18
|
7 | .map(|p| p.display())
| ^ - `p` dropped here while still borrowed
| |
| borrowed value does not live long enough
...
18 | }
| - borrowed value needs to live until here
What is the reason of that mistake? What is the solution?