Function inquire::prompt_usize
source · pub fn prompt_usize<M>(message: M) -> InquireResult<usize>
Expand description
This function is a helpful one-liner to prompt the user for a number and parse it to usize.
Under the hood, it is equivalent to calling inquire::CustomType::<usize>::new(message).prompt()
.
See the documentation for [inquire::CustomType
] for more information on its behavior.
§Arguments
message
: A message that implements theAsRef<str>
trait. This message will be displayed to the user when asking for input.
§Returns
InquireResult<usize>
: An enum that represents the result of the prompt operation. If the operation is successful, it returnsInquireResult::Ok(usize)
where usize is the number parsed from the user’s input. If the operation encounters an error, it returnsInquireResult::Err(InquireError)
.
§Example
let kilograms = prompt_usize("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
.