pub enum ParsingError {
InvalidOption {
reason: &'static str,
offender: Option<String>,
},
UnconsumedValue {
value: String,
},
Empty,
UnexpectedArg {
offender: String,
value: Option<String>,
format: &'static str,
prefix: &'static str,
},
}Expand description
Errors that can occur during argument parsing.
All parsing operations return a Result with this error type. Each variant
provides specific context about what went wrong during parsing.
Variants§
InvalidOption
Invalid option syntax or format was encountered.
This typically occurs when:
- Short options are given values with
=syntax (e.g.,-x=value) - Malformed option syntax is detected
§Fields
reason- Human-readable description of what was invalidoffender- The specific argument that caused the error (if available)
UnconsumedValue
An option value was not consumed after being parsed.
This occurs when a long option has an attached value (e.g., --file=input.txt)
but the application doesn’t call Parser::value or Parser::ignore_value
before parsing the next argument.
§Fields
value- The unconsumed value that was attached to the option
Empty
The argument iterator was empty (contained no program name).
This should not occur during normal program execution but may happen when creating parsers from empty custom iterators.
UnexpectedArg
An unexpected or unrecognized argument was encountered.
This error is typically created by calling Argument::into_error when
the application encounters an argument it doesn’t know how to handle.
§Fields
offender- The argument name that was unexpectedvalue- Associated value (if any)format- How the value is formatted in error messages (e.g., “=” or “ “)prefix- The argument prefix (e.g., “–” for long options, “-” for short)