How to check for EOF in read_line in Rust 1.12?
<p>Consider the following program, how do I detect EOF in stdin and break the loop?</p>

<pre><code>use std::io;
use std::process;

fn main() {
    let mut sum = 0;
    loop {
        let mut number_str = String::new();
        match io::stdin().read_line(&amp;mut number_str) {
            Ok(n) =&gt; {},
            Err(e) =&gt; { println!("ERROR: got '{}' when reading a line", e) }
        }
        match number_str.trim().parse::&lt;i32&gt;() {
            Err(n) =&gt; {
                println!("ERROR: Entered something that is not a number: '{}'",
                    number_str.trim_right());
                process::exit(1)
            },
            Ok(n) =&gt; { sum += n }
        }
    }
}
</code></pre>

<p><strong>Note</strong>: there is an <a href="https://stackoverflow.com/q/27475113/1091116">identical question</a> but the answer seems to be out of date anymore, which is why I added a version number in the question title.</p>