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
Required Methods§
Sourcefn parse(&self, args: impl IntoIterator<Item = OsString>) -> Args
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_parsemethod but additionally wrap error handling logic
§Arguments
args- The CLI args to be parsed. Typically retrieved fromstd::env::args_os.
§Returns
An owned instance of Args containing parsing result of given args.
Sourcefn try_parse(
&self,
args: impl IntoIterator<Item = OsString>,
) -> Result<Args, ProgramExit>
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
Argsfor more infos)
§Arguments
args- The CLI args to be parsed. Typically retrieved fromstd::env::args_os.
§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.