title: What is unwrap in Rust, and what is it used for?
body: <p>I have this code that uses <code>.unwrap()</code>:</p>
  
  <pre><code>fn main() {
      let paths = std::fs::read_dir("/home/user").unwrap();
  
      for path in paths {
          println!("Name: {}", path.unwrap().path().display());
  
      }
  }
  </code></pre>
  
  <p>After looking at the <a href="https://github.com/rust-lang/rust/blob/53498eca50e25d8a11f9dc5859770715fa906fa7/src/libcore/result.rs#L684-L689" rel="noreferrer">definition of <code>unwrap</code></a>,</p>
  
  <pre><code>pub fn unwrap(self) -&gt; T {
    match self {
          Ok(t) =&gt; t,
          Err(e) =&gt; unwrap_failed("called `Result::unwrap()` on an `Err` value", e),
      }
  }
  </code></pre>
  
  <p>And the <a href="https://github.com/rust-lang/rust/blob/53498eca50e25d8a11f9dc5859770715fa906fa7/src/libstd/fs.rs#L1351-L1353" rel="noreferrer">signature of <code>read_dir</code></a></p>
  
  <pre><code>pub fn read_dir&lt;P: AsRef&lt;Path&gt;&gt;(path: P) -&gt; io::Result&lt;ReadDir&gt;
  </code></pre>
  
  <p>Am I correct in understanding that <code>unwrap</code> returns the <code>T</code> type that is passed in <code>Result</code>?</p>