Trait ArgsParser

Source
pub trait ArgsParser {
    // Required methods
    fn parse(&self, args: impl IntoIterator<Item = OsString>) -> Args;
    fn try_parse(
        &self,
        args: impl IntoIterator<Item = OsString>,
    ) -> Result<Args, ProgramExit>;
}
Expand description

Cli args parser trait to parse CLI args and return them in an Args.

The produced Args instance needs to comply with constraints of each one of its fields (see fields doc in Args for more infos).

Required Methods§

Source

fn parse(&self, args: impl IntoIterator<Item = OsString>) -> Args

Parses given cli args and return them as an Args instance.

  • First CLI args should be the binary name
  • Rely on ArgsParser::try_parse method but additionally wrap error handling logic
§Arguments
§Returns

An owned instance of Args containing parsing result of given args.

Source

fn try_parse( &self, args: impl IntoIterator<Item = OsString>, ) -> Result<Args, ProgramExit>

Parses given cli args and return them as an Args instance if no error or early exit occurred.

  • First CLI args should be the binary name
  • Version, author and help options are considered as early program exit
  • Returned Args complies with expected constraints (see fields doc in Args for more infos)
§Arguments
§Returns

A result containing an owned instance of Args if successful parsing, or a ProgramExit if any error or early exit occurred (e.g. version/ author/help infos printing, invalid cli args…)

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§