ArgsExt

Trait ArgsExt 

Source
pub trait ArgsExt: IntoIterator<Item = String> + Sized {
    // Provided method
    fn opts(self, short_pairs: &str) -> Result<Parser, NonAlphaNumError> { ... }
}
Expand description

Converts Iterator of Strings into an iterator of Opts.

Provided Methods§

Source

fn opts(self, short_pairs: &str) -> Result<Parser, NonAlphaNumError>

Parses an Iterator using Parser.

Returns None if short_pairs has non-alphanumeric characters.

§Examples
$ program arg1 -abcx12 -y 3 --long --key=value - arg2 -- -kh --ignore

The following code simulates parsing of the command above:

use argsyn::ArgsExt;

let cmd = "program arg1 -abcx12 -y 3 --long --key=value - arg2 -- -kh --ignore";

let args = cmd
  .split_ascii_whitespace()
  .into_iter()
  .map(|s| s.to_string());

for opt in args.opts("xy").unwrap() {
  println!("{:?}", opt);
}

Running the above code produces the following output:

NonOption("program")
NonOption("arg1")
Short("a")
Short("b")
Short("c")
ShortPair("x", "12")
ShortPair("y", "3")
Long("long")
LongPair("key", "value")
Dash
NonOption("arg2")
Terminator
NonOption("-kh")
NonOption("--ignore")

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> ArgsExt for T
where T: IntoIterator<Item = String>,