Type Alias inquire::formatter::MultiOptionFormatter
source · pub type MultiOptionFormatter<'a, T> = &'a dyn Fn(&[ListOption<&T>]) -> String;
Expand description
Type alias for formatters used in MultiSelect
prompts.
Formatters receive the user input and return a String to be displayed to the user as the final answer.
§Examples
use inquire::list_option::ListOption;
use inquire::formatter::MultiOptionFormatter;
let formatter: MultiOptionFormatter<str> = &|opts| {
let len = opts.len();
let options = match len {
1 => "option",
_ => "options",
};
format!("You selected {} {}", len, options)
};
let mut ans = vec![ListOption::new(0, "a")];
assert_eq!(String::from("You selected 1 option"), formatter(&ans));
ans.push(ListOption::new(3, "d"));
assert_eq!(String::from("You selected 2 options"), formatter(&ans));