Macro inquire::parse_type
source · macro_rules! parse_type { ($type:ty) => { ... }; }
Expand description
Built-in parser creator that checks whether the answer is able to be successfully
parsed to a given type, such as f64
.
The given type must implement the FromStr trait.
§Arguments
$type
- Target type of the parsing operation.
§Examples
use inquire::parse_type;
use inquire::parser::CustomTypeParser;
let parser: CustomTypeParser<f64> = parse_type!(f64);
assert_eq!(Ok(32.44f64), parser("32.44"));
assert_eq!(Ok(11e15f64), parser("11e15"));
assert_eq!(Err(()), parser("32f"));
assert_eq!(Err(()), parser("11^2"));