-
|
I'm new to Clap and Rust in general and I really like Clap so far. The guide I'm following uses Clap 3 and uses the
Is this the new recommended way even if I just want to validate, but let Clap parse as usual? In case it matters, I need to check if the arg matches a certain regex. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Yes, this is the new way. The idea is to put the emphasis on parsing into a validated type ("parse, don't validate") but it does not preclude validating to a non-validated type. Say you want to validate a string, you can use |
Beta Was this translation helpful? Give feedback.
-
|
I understand. Thanks for answering 😊 |
Beta Was this translation helpful? Give feedback.
Yes, this is the new way. The idea is to put the emphasis on parsing into a validated type ("parse, don't validate") but it does not preclude validating to a non-validated type.
Say you want to validate a string, you can use
clap::builder::StringValueParser::new().try_map(|s| ...). A short-cut for this is to pass in aFn(&str) -> Result<T, E>(and you can just return aStringasT) as a value parser.