Function inquire::prompt_text

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

This function is a helpful one-liner to prompt the user for a text input.

Under the hood, it is equivalent to calling inquire::Text::new(message).prompt(). See the documentation for [inquire::Text] 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 input.

§Returns

  • InquireResult<String>: An enum that represents the result of the prompt operation. If the operation is successful, it returns InquireResult::Ok(String) where the String represents the user’s input. If the operation encounters an error, it returns InquireResult::Err(InquireError).

§Example

let name = prompt_text("What is your name?")?;

§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.