pub struct Matcher<O: Default = DefaultTagType, P: Default = DefaultTagType> { /* private fields */ }
Expand description

Contains a set of filters which can be used to match one or more arguments in a command line. An argument must meet all filter conditions in a matcher for a match to occur.

The following filters are supported:

Before parsing a command line, the Parser instance should be assigned one or more Matcher instance. When a command line is parsed, all arguments must be matched by a matcher. If zero matchers are assigned to a Parser, then all arguments will be matched.

It is possible for an argument to be matched by more than one matcher. For each argument, the parser will attempt to match a matcher in the order of Parser.matchers. If a one matcher is more specific than another, insert it into this vector before the other.

Each argument produced by the Parser’s parse functions (parse_line, parse_env, parse_env_args), will include a reference to the matcher which matched it. The properties of a matcher can be used by the application when processing an argument. The Matcher.option_tag and Matcher.param_tag can be assigned enums to assist with this processing. These enums can be used in match arms to easily identify arguments.

Implementations

Create a new matcher with the specified name.

Create a new matcher with the specified name which matches option arguments.

Create a new matcher with the specified name which matches parameter arguments.

Get the name of a matcher.

This is used for display and help purposes. It is not used as a match filter.

Set the name of a matcher.

Get the index of the matcher within the Parser’s matchers vector.

Get the help text associated with a matcher

Set the help text associated with a matcher as an Option

Set the help text associated with a matcher

Clear the help text associated with a matcher

A value that can be used to identify option arguments matched by a matcher. Is of the type specified by the Parser’s O generic parameter. Normally O is an enum type which can be used in match statements which process the array of Arg variants returned by a parse function.

Set the option tag value. See option_tag.

A value that can be used to identify parameter arguments matched by a matcher. Is of the type specified by the Parser’s P generic parameter. Normally P is an enum type which can be used in match statements which process the array of Arg variants returned by a parse function.

Set the parameter tag value. See param_tag.

Match Filter: If None, all arguments accepted. Otherwise accepts an argument whose index is included in the vector.

Match Filter: Get the arg_indices as a slice.

Match Filter: Set arg_indices.

Match Filter: Set arg_indices from an array of usize.

Match Filter: Set arg_indices to None so that it accepts all arguments.

Match Filter: If None, accepts all arguments. Otherwise accepts arguments of the type specified.

Match Filter: Set arg_type.

Match Filter: Set the arg_type to a type value.

Match Filter: Set arg_type to None so that it accepts all arguments.

Match Filter: If None, all arguments accepted. Otherwise accepts a parameter argument whose index is included in the vector.

Match Filter: Get the param_indices as a slice.

Match Filter: Set param_indices.

Match Filter: Set param_indices from an array of usize.

Match Filter: Set param_indices to None so that it accepts all arguments.

Match Filter: If None, all arguments accepted. Otherwise accepts an option argument whose index is included in the vector.

Match Filter: Get the option_indices as a slice.

Match Filter: Set option_indices.

Match Filter: Set option_indices from an array of usize.

Match Filter: Set option_indices to None so that it accepts all arguments.

Match Filter: If None, all arguments accepted. Otherwise accepts an option argument whose code is matched by any of the RegexOrText in the vector.

Match Filter: Get the option_codes RegexOrTexts as a slice.

Match Filter: Set option_codes.

Match Filter: Set option_codes from an array of RegexOrText.

Match Filter: Set option_codes to None so that it accepts all arguments.

Match Filter: Accepts an option argument with or without an option value according to the OptionHasValue variant. (Default: Never)

Match Filter: Set option_has_value.

Match Filter: Specifies whether an option argument with a value which starts with an option announcer character is accepted.

Option values beginning with an option announcer character can be both confusing and convenient. If they can start with option announcers, they may easily be confused with being a separate option. However they can be convenient, for example, if the option value specifies numbers that can be negative (assuming ‘-’ is the option announcer). Whether to allow option values to begin with an option announcer will depend on the context.

To start an option value with an option announcer when this is not allowed, the value should either be enclosed in quotes or the announcer should be escaped.

Currently starting an option value with an option announcer when option_has_value is IfPossible is not supported.

Match Filter: If None, all arguments accepted. Otherwise, if argument is a parameter, then the argument will be accepted if the parameter’s text is matched by the RegexOrText. If the argument is an option and has a value, then the argument is accepted if the option value text is matched by the RegexOrText. In all other cases, the argument is accepted.

Match Filter: Set value_text.

Match Filter: Set value_text to a RegexOrText.

Match Filter: Set value_text to None so that it accepts all arguments.

Trait Implementations

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.