use std::io;
fn main() {
let mut input = String::new();
while io::stdin().read_line(&mut input).is_ok() {
println!("{:?}", input);
input.clear();
}
println!("How could I reach here?");
}
When I input an arbitrary string, the program echoes it back; when I send EOF with Ctrl+D, it prints an empty string; when I send SIGINT with Ctrl+C, it simply exits. As a user, (how) can I make io::stdin().read_line return an Err?
BTW you should also check Ok(usize) which is the number of bytes read. If it's 0/empty, the input has been closed and no more data will be read, see BufRead in std::io - Rust .