Function inquire::prompt_confirmation

source ·
pub fn prompt_confirmation<M>(message: M) -> InquireResult<bool>
where M: AsRef<str>,
Expand description

This function is a helpful one-liner to prompt the user for the confirmation of an action.

Under the hood, it is equivalent to calling inquire::Confirm::new(message).prompt(). See the documentation for [inquire::Confirm] for more information on its behavior.

§Arguments

  • message: A message that implements the AsRef<str> trait. This message will be displayed to the user when asking for confirmation.

§Returns

  • InquireResult<bool>: An enum that represents the result of the prompt operation. If the operation is successful, it returns InquireResult::Ok(bool) where the bool represents the user’s answer to the confirmation prompt. true is for “yes” and false is for “no”. If the operation encounters an error, it returns InquireResult::Err(InquireError).

§Example

match prompt_confirmation("Are you sure you want to continue?") {
    InquireResult::Ok(true) => println!("User confirmed."),
    InquireResult::Ok(false) => println!("User did not confirm."),
    InquireResult::Err(err) => println!("An error occurred: {}", err),
}

§Errors

This function will return an error if there is a problem interacting with the terminal, or if the user cancels the operation by pressing Ctrl+C.