title: What's the de-facto way of reading and writing files in Rust 1.x?
body: <p>With Rust being comparatively new, I've seen far too many ways of reading and writing files. Many are extremely messy snippets someone came up with for their blog, and 99% of the examples I've found (even on Stack Overflow) are from unstable builds that no longer work. Now that Rust is stable, what is a simple, readable, non-panicking snippet for reading or writing files?</p>
  
  <p>This is the closest I've gotten to something that works in terms of reading a text file, but it's still not compiling even though I'm fairly certain I've included everything I should have. This is based off of a snippet I found on Google+ of all places, and the only thing I've changed is that the old <code>BufferedReader</code> is now just <code>BufReader</code>:</p>
  
  <pre><code>use std::fs::File;
  use std::io::BufReader;
  use std::path::Path;
  
  fn main() {
      let path = Path::new("./textfile");
      let mut file = BufReader::new(File::open(&amp;path));
      for line in file.lines() {
          println!("{}", line);
      }
  }
  </code></pre>
  
  <p>The compiler complains:</p>
  
  <pre class="lang-none prettyprint-override"><code>error: the trait bound `std::result::Result&lt;std::fs::File, std::io::Error&gt;: std::io::Read` is not satisfied [--explain E0277]
   --&gt; src/main.rs:7:20
    |&gt;
  7 |&gt;     let mut file = BufReader::new(File::open(&amp;path));
    |&gt;                    ^^^^^^^^^^^^^^
  note: required by `std::io::BufReader::new`
  
  error: no method named `lines` found for type `std::io::BufReader&lt;std::result::Result&lt;std::fs::File, std::io::Error&gt;&gt;` in the current scope
   --&gt; src/main.rs:8:22
    |&gt;
  8 |&gt;     for line in file.lines() {
    |&gt;                      ^^^^^
  </code></pre>
  
  <p>To sum it up, what I'm looking for is:</p>
  
  <ul>
  <li>brevity</li>
  <li>readability</li>
  <li>covers all possible errors</li>
  <li>doesn't panic</li>
  </ul>