get_bool

Function get_bool 

Source
pub fn get_bool(prompt: &str) -> bool
Expand description

Prompts the user for a boolean input, returning true if the input is “y” or “yes” (case insensitive), and false if the input is “n” or “no” (case insensitive). If the input does not match either “y”, “yes”, “n”, or “no”, the function will loop and prompt the user again.

§Arguments

  • prompt - A string slice that will be displayed to the user as the prompt for their input.

§Example

use user_input::{get_bool};

let confirm = get_bool("Are you sure you want to proceed? (y/n) ");
if confirm {
    println!("User confirmed.");
} else {
    println!("User declined.");
}