macro_rules! input {
() => { ... };
($($arg:tt)*) => { ... };
}Expand description
A macro that:
- optionally prints a prompt (with
print!). - reads one line from stdin.
- returns
Err(InputError::Eof)if EOF is encountered. - returns
Err(InputError::Parse(e))if the input cannot be parsed. - returns
Err(InputError::Io(e))if an IO error occurs.
ยงUsage:
// No prompt
let text: String = input!().unwrap();
// With prompt
let name: String = input!("Enter your name: ").unwrap();
// Formatted prompt
let user = "Alice";
let age: String = input!("Enter {}'s age: ", user).unwrap();