Skip to main content

prompt

Function prompt 

Source
pub fn prompt<T>(
    prompt: &(impl ToString + Display + ?Sized),
) -> Result<T, <T as FromStr>::Err>
where T: FromStr + 'static,
Expand description

Creates a CLI prompt and asks the user for input.

ยงExample

use read_stdin;

let Ok(n) = read_stdin::prompt::<i32>("Enter a number: ") else {
    println!("Failed to parse");
    return;
};

println!("You entered: {}", n);