Expand description
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!");
}
}
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();
Structs§
- Args
Native - An iterator over native command line
Argument
s. - Argument
- A command line argument.
- Parser
- A parsing iterator that produces
Token
s.
Enums§
Functions§
- args_
native - An iterator over the program’s command line
Argument
s - null_
separated_ list - A list of arguments separated by a
\0
character. - null_
separated_ list_ wide - A list of UTF-16 encoded arguments, separated by a NULL.