Closed
Description
Here's a mini version of code I destilled from my attempts to deal with env::args.
// Why does this fail, and how can I fix it?
use std::env;
fn main() {
let mut vec0: Vec<&str> = vec![];
let vec1: Vec<_> = env::args().collect();
let s = vec1.get(0).unwrap(); // `vec1` does not live long enough
vec0.push(&s);
}
// Note: this does compile:
// fn main() {
// let mut vec0: Vec<&str> = vec![];
// let vec1: Vec<_> = vec!["foo", "bar"];;
// let s = vec1.get(0).unwrap();
// vec0.push(&s);
// }
I'd appreciate some help and explanation - I've tried a lot already, using to_owned() etc.
What I wanted to do: learn rust by writing code. Here I wanted to deal with program parameters (intentionally ignoring the libs crates.io).
Metadata
Metadata
Assignees
Labels
No labels