pub fn read_and_parse_with_prompt<T: FromStr>(
prompt: &str,
) -> Result<T, InputError<T::Err>>
Expand description
Like read_and_parse
, but prints a prompt before reading.
This function is useful for interactive programs. It prints the provided prompt
,
then waits for user input. The input is then parsed into T
or yields an error.
§Errors
Returns InputError::Io
on read errors.
Returns InputError::Parse
if the input cannot be parsed into T
.
§Examples
let value: i32 = read_and_parse_with_prompt("Enter a number: ").unwrap();
println!("You entered: {}", value);