Method lrs::getopt::Getopt::used

Returns the number of arguments used before parsing was stopped.

Syntax

impl<'a, I> Getopt<'a, I>
    where I: Iterator<Item = &'static CStr>,
{
    fn used(&self) -> usize
}

Remarks

This can be used when parsing arguments that contain trailing data, e.g.,

Usage: my_program [OPTIONS]* file_name

Examples

let mut args = env::args();
args.next(); // skip program name

let mut getopts = Getopt::new(args, &[]);
for (arg, param) in &mut getopts {
    // ...
}

// Add 1 to getopts.used() because we have to skip the program name
println!("file_name: {:?}", env::args().consume(1+getopts.used()).next());

Note that both of the following invocations will print the correct file name:

my_program my_file
my_program -- my_file

Prints

file_name: "my_file"
file_name: "my_file"