[−][src]Function read_human::read_choice
pub fn read_choice(
question: &str,
options: &[impl AsRef<str>],
default: Option<usize>
) -> Result<usize>
Allow the user to choose between a set of choices, and optionally give them a default choice.
The default will be selected if the user just hits enter. If the user writes something that's not one of the choices, the function will ask for another line of input.
Panics
This function will panic if the default value is >= the number of options.
Examples
let choice = read_human::read_choice("What is your gender?", &["male", "female"], None)?; // Must be 0 (male) or 1 (female) assert!(choice <= 2);