get_number

Function get_number 

Source
pub fn get_number<T: PartialOrd + Display + FromStr + Copy>(
    prompt: Option<&str>,
    repeat_message: Option<&str>,
    min_value: Option<T>,
    max_value: Option<T>,
) -> T
Expand description

Prompts the user for a number input and returns it.

§Arguments

  • prompt - An option that can contain a string slice which holds the prompt to present the user with.
  • repeat_message - An option that can contain a string slice which holds a repeat message which will be displayed if the user enters invalid input
  • min_value - An option that can contain a number of type T which specifies the minimum value the user can input.
  • max_value - An option that can contain a number of type T which specifies the maximum value the user can input.

§Example

use simple_cli::*;
let input = get_number::<i8>(Some("Enter an integer from 0 to 10:"), None, Some(0), Some(10));

let float_input = get_number::<f32>(Some("Enter a float from 0 to 10:"), None, Some(0.0), Some(10.0));