Trait TypedValueParser
trait TypedValueParser: Clone + Send + Sync + 'static
Parse/validate argument values
As alternatives to implementing TypedValueParser,
- Use
Fn(&str) -> Result<T, E>which implementsTypedValueParser TypedValueParser::maporTypedValueParser::try_mapto adapt an existingTypedValueParser
See ValueParserFactory to register TypedValueParser::Value with
[value_parser!][crate::value_parser].
Example
#
Associated Types
type Value: TraitBound { trait_: Path { path: "Send", id: Id(93), args: None }, generic_params: [], modifier: None } + TraitBound { trait_: Path { path: "Sync", id: Id(95), args: None }, generic_params: [], modifier: None } + TraitBound { trait_: Path { path: "Clone", id: Id(10), args: None }, generic_params: [], modifier: None }Argument's value type
Required Methods
fn parse_ref(self: &Self, cmd: &Command, arg: Option<&Arg>, value: &OsStr) -> Result<<Self as >::Value, Error>Parse the argument value
When
argisNone, an external subcommand value is being parsed.
Provided Methods
fn parse_ref_(self: &Self, cmd: &Command, arg: Option<&Arg>, value: &OsStr, _source: ValueSource) -> Result<<Self as >::Value, Error>Parse the argument value
When
argisNone, an external subcommand value is being parsed.fn parse(self: &Self, cmd: &Command, arg: Option<&Arg>, value: OsString) -> Result<<Self as >::Value, Error>Parse the argument value
When
argisNone, an external subcommand value is being parsed.fn parse_(self: &Self, cmd: &Command, arg: Option<&Arg>, value: OsString, _source: ValueSource) -> Result<<Self as >::Value, Error>Parse the argument value
When
argisNone, an external subcommand value is being parsed.fn possible_values(self: &Self) -> Option<Box<dyn Iterator<Item = PossibleValue> + '_>>Reflect on enumerated value properties
Error checking should not be done with this; it is mostly targeted at user-facing applications like errors and completion.
fn map<T, F>(self: Self, func: F) -> MapValueParser<Self, F> where T: Send + Sync + Clone, F: Fn(<Self as >::Value) -> T + CloneAdapt a
TypedValueParserfrom one value to anotherExample
# use clap_builder as clap; # use Command; # use Arg; # use TypedValueParser as _; # use BoolishValueParser; let cmd = new .arg; let matches = cmd.clone.try_get_matches_from.unwrap; assert!; assert_eq!; let matches = cmd.try_get_matches_from.unwrap; assert!; assert_eq!;fn try_map<T, E, F>(self: Self, func: F) -> TryMapValueParser<Self, F> where F: Fn(<Self as >::Value) -> Result<T, E> + Clone + Send + Sync + 'static, T: Send + Sync + Clone, E: Into<Box<dyn Error + Send + Sync + 'static>>Adapt a
TypedValueParserfrom one value to anotherExample
# use clap_builder as clap; # use OsString; # use OsStr; # use PathBuf; # use Path; # use Command; # use Arg; # use TypedValueParser as _; # use OsStringValueParser; let cmd = new .arg; let error = cmd.clone.try_get_matches_from.unwrap_err; error.print; let matches = cmd.try_get_matches_from.unwrap; assert!; assert_eq!;
Implementors
impl<P, F, T, E> TypedValueParser for TryMapValueParser<P, F>impl TypedValueParser for NonEmptyStringValueParserimpl<T: TryFrom<i64> + Clone + Send + Sync + 'static> TypedValueParser for RangedI64ValueParser<T>impl<P, F, T> TypedValueParser for MapValueParser<P, F>impl TypedValueParser for StringValueParserimpl TypedValueParser for OsStringValueParserimpl TypedValueParser for PathBufValueParserimpl<E: crate::ValueEnum + Clone + Send + Sync + 'static> TypedValueParser for EnumValueParser<E>impl TypedValueParser for BoolishValueParserimpl<F, T, E> TypedValueParser for Fimpl TypedValueParser for PossibleValuesParserimpl TypedValueParser for BoolValueParserimpl TypedValueParser for FalseyValueParserimpl<T: TryFrom<u64> + Clone + Send + Sync + 'static> TypedValueParser for RangedU64ValueParser<T>impl TypedValueParser for UnknownArgumentValueParser