I am trying to create a vector Stringto check arg parsing (as this is what returns std::env::args()), but struggling with how to do it briefly.
What I want:
let test_args = vec!["-w", "60", "arg"];
let expected_results = my_arg_parser(test_args);
This clearly does not work, because the contents of the vectors are all &strs.
Usage String::from, but works, but does not scale well and ugly :)
let args = vec![String::from("-w"), String::from("60"), String::from("args")];
I could match the links and return the string objects, but that looks a lot:
let args = vec!["-w", "60", "args"].iter().map(|x| x.to_string()).collect::<Vec<String>>();
Should I just create a helper function for the conversion, or is there an easier way?
source
share