Trait TypedValueParser
pub 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: Send + Sync + Clone;Argument's value type
Required Methods
fn parse_ref(&self, cmd: &Command, arg: Option<&Arg>, value: &OsStr) -> Result<Self::Value, Error>Parse the argument value
When
argisNone, an external subcommand value is being parsed.
Provided Methods
fn parse_ref_(&self, cmd: &Command, arg: Option<&Arg>, value: &OsStr, _source: ValueSource) -> Result<Self::Value, Error>Parse the argument value
When
argisNone, an external subcommand value is being parsed.fn parse(&self, cmd: &Command, arg: Option<&Arg>, value: OsString) -> Result<Self::Value, Error>Parse the argument value
When
argisNone, an external subcommand value is being parsed.fn parse_(&self, cmd: &Command, arg: Option<&Arg>, value: OsString, _source: ValueSource) -> Result<Self::Value, Error>Parse the argument value
When
argisNone, an external subcommand value is being parsed.fn possible_values(&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, func: F) -> MapValueParser<Self, F> where T: Send + Sync + Clone, F: Fn(Self::Value) -> T + Clone,Adapt 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, func: F) -> TryMapValueParser<Self, F> where F: Fn(Self::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 TypedValueParser for BoolValueParserimpl TypedValueParser for BoolishValueParserimpl TypedValueParser for FalseyValueParserimpl TypedValueParser for NonEmptyStringValueParserimpl TypedValueParser for OsStringValueParserimpl TypedValueParser for PathBufValueParserimpl TypedValueParser for PossibleValuesParserimpl TypedValueParser for StringValueParserimpl TypedValueParser for UnknownArgumentValueParserimpl<E: ValueEnum + Clone + Send + Sync + 'static> TypedValueParser for EnumValueParser<E>impl<F, T, E> TypedValueParser for F where F: Fn(&str) -> Result<T, E> + Clone + Send + Sync + 'static, E: Into<Box<dyn Error + Send + Sync + 'static>>, T: Send + Sync + Clone,impl<P, F, T> TypedValueParser for MapValueParser<P, F> where P: TypedValueParser, P::Value: Send + Sync + Clone, F: Fn(P::Value) -> T + Clone + Send + Sync + 'static, T: Send + Sync + Clone,impl<P, F, T, E> TypedValueParser for TryMapValueParser<P, F> where P: TypedValueParser, P::Value: Send + Sync + Clone, F: Fn(P::Value) -> Result<T, E> + Clone + Send + Sync + 'static, T: Send + Sync + Clone, E: Into<Box<dyn Error + Send + Sync + 'static>>,impl<T: TryFrom<i64> + Clone + Send + Sync + 'static> TypedValueParser for RangedI64ValueParser<T> where <T as TryFrom<i64>>::Error: Send + Sync + 'static + Error + ToString,impl<T: TryFrom<u64> + Clone + Send + Sync + 'static> TypedValueParser for RangedU64ValueParser<T> where <T as TryFrom<u64>>::Error: Send + Sync + 'static + Error + ToString,