Function read_stdin::read_stdin

source ·
pub fn read_stdin<T>() -> Result<T, <T as FromStr>::Err>where
    T: FromStr + 'static,
Expand description

Read user input from stdin and try to parse it into a generic type.

Example

use read_stdin::read_stdin;
 
let Ok(n) = read_stdin::<i32>() else {
    println!("You entered an incorrect data type!");
    return;
};
 
println!("You entered: {}", n)