Function read_bool

Source
pub fn read_bool(msg: Option<&str>, err_msg: Option<&str>) -> bool
Expand description

§ARGUMENTS

‘msg’ (Option<&str>) - an optional message which will be printed at the same line as the input prompt. Must be set to Some(“…”) or None.

‘err_msg’ (Option<&str>) - an optional error message which will be printed if the user inputs an invalid value. Must be set to Some(“…”) or None.

§DESCRIPTION

Prompts the user to type a boolean value (bool) manually, which will then be returned. This function is not case-sensitive, so values like True or fAlSe will still work. In case the user writes an invalid value, they will be prompted to try again.

Provides an information message on the same line as the prompt if Some(“…”) is provided, and just the prompt if None is provided.

If err_msg is set to None, a default message will be shown.

§RETURNS

A boolean value (bool) provided by the user.

§EXAMPLES

use quick_input::read_bool;
let user_bool_with_msg = read_bool(Some("Please input a boolean value: "), Some("Please input true or false."));

let user_bool: bool = read_bool(None, None);