Type Alias inquire::parser::CustomTypeParser
source · pub type CustomTypeParser<'a, T> = &'a dyn Fn(&str) -> Result<T, ()>;
Expand description
Type alias for parsers used in Confirm prompts.
CustomTypeParser
s receive the user input to a given prompt and return either
a successful result (Ok) containing the parsed bool
or an empty Err
if a value could not be parsed.
§Examples
use inquire::parser::CustomTypeParser;
let parser: CustomTypeParser<bool> = &|val| match val {
"si" => Ok(true),
"no" => Ok(false),
_ => Err(()),
};
assert_eq!(Ok(true), parser("si"));
assert_eq!(Ok(false), parser("no"));
assert_eq!(Err(()), parser("yes"));
assert_eq!(Err(()), parser("não"));