Function inquire::prompt_f32

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

This function is a helpful one-liner to prompt the user for a number and parse it to f32.

Under the hood, it is equivalent to calling inquire::CustomType::<f32>::new(message).prompt(). See the documentation for [inquire::CustomType] 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<f32>: An enum that represents the result of the prompt operation. If the operation is successful, it returns InquireResult::Ok(f32) where f32 is the number parsed from the user’s input. If the operation encounters an error, it returns InquireResult::Err(InquireError).

§Example

let kilograms = prompt_f32("Weight (kg):")?;

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