aj_io_tools::input

Function read_line_as

Source
pub fn read_line_as<T: Default + FromStr>(message: &str) -> T
Expand description

Scans the input to the console by first printing an invitation message to the console and finally parsing it into a specific type, declared in turbofish.

§Params

  • message: &str - Invitation message to the console.

§Returns

  • Turbofish typed (T) object.

§Panics

If somehow failed to read line with stdin().read_line() function.

§Examples

use aj_io_tools::read_line_as;
 
let input = read_line_as::<u8>("How old are you: ");
 
match input {
    23 => println!("Wow, your life is just starting!"),
    _ => println!("Wow, your life is just starting, but you're not 23!")
}