2 unstable releases

0.2.0 Jul 27, 2021
0.1.0 Jul 27, 2021

#161 in Windows APIs

25 downloads per month

MIT/Apache

17KB
525 lines

The Windows command line is passed to applications as a string. To get an array of arguments it's necessary to parse this string, which is what this crate does. This list of arguments can then be used by higher level argument parsers.

It uses the latest C/C++ parsing rules so that it is consistent with using argv from a C/C++ program.

Using

Add this to your Cargo.toml file

[dependencies.winarg]
version = "0.2.0"

Example

for arg in winarg::args_native().skip(1) {
    if arg == "--help" {
        println!("help me!");
    }
}

lib.rs:

The Windows command line is passed to applications as a string. To get an array of arguments it's necessary to parse this string, which is what this crate does. This list of arguments can then be used by higher level argument parsers.

It uses the latest C/C++ parsing rules so that it is consistent with using argv from a C/C++ program.

Using

Add this to your Cargo.toml file

[dependencies.winarg]
version = "0.2.0"

Examples

Creating a single String buffer to hold a list of arguments using null_separated_list:

let args: String = winarg::null_separated_list().collect();
for arg in args.split('\0') {
    println!("{}", arg);
}

Iterating arguments without allocation using args_native:

for arg in winarg::args_native().skip(1) {
    if arg == "--help" {
        println!("help me!");
    }
}

[struct@Parser] can be used to create custom constructs. For example:

let mut parser = winarg::Parser();
// Skip the zeroth argument.
for t in &mut parser {
    if t.is_next_arg() { break; }
}
// Collect the rest into a UTF-16 encoded vector.
let args: Vec<u16> = parser.map(|t| t.as_u16() ).collect();

No runtime deps