I am making a new program and I have a function specifically for parsing command line arguments given to it. I loop over a Vec<String>
reference and for each loop, I use a match
expression to find a -o argument. If it's found, I store the output name in a variable named program_output_name
by calling args.next(). But I get the error no method named
next found for type 'std::vec::Vec<std::string::String>' in the current scope
. How do I get the next iteration of args to get the output name?
Code:
fn parse_command_line_args(args: Vec<String>, compile_args_global: &mut CompilerArgs) {
// This is used to keep track of the number of input files given
let mut total_input_files = 0;
for arg in &args {
match arg.as_str() {
"-o" => {
let program_ouput_name = args.next();
// do something with program_ouput_name
}
_ => ()
}
}
}