input_macro

Function read_and_parse

Source
pub fn read_and_parse<T: FromStr>() -> Result<T, InputError<T::Err>>
where T::Err: Debug + Display,
Expand description

Reads and parses a single line from stdin into a desired type T.

This function locks stdin, reads one line, trims it, and attempts to parse it into T. If an error occurs during reading or parsing, an InputError is returned.

§Errors

Returns InputError::Io on read errors.
Returns InputError::Parse if the input doesn’t parse into the desired type.

§Examples

// Not testable directly in a doc test since it reads from stdin, but usage is straightforward:
// let value: i32 = read_and_parse().unwrap();