title: How to check whether a path exists?
body: <p>The choice seems to be between <code>std::fs::PathExt</code> and <code>std::fs::metadata</code>, but the latter is suggested for the time being as it is more stable. Below is the code I have been working with as it is based off the docs:</p>
  
  <pre><code>use std::fs;
  
  pub fn path_exists(path: &amp;str) -&gt; bool {
      let metadata = try!(fs::metadata(path));
      assert!(metadata.is_file());
  }
  </code></pre>
  
  <p>However, for some odd reason <code>let metadata = try!(fs::metadata(path))</code> still requires the function to return a <code>Result&lt;T,E&gt;</code> even though I simply want to return a boolean as shown from <code>assert!(metadata.is_file())</code>.</p>
  
  <p>Even though there will probably be a lot of changes to this soon enough, how would I bypass the <code>try!()</code> issue? </p>
  
  <p>Below is the relevant compiler error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
   --&gt; src/main.rs:4:20
    |
  4 |     let metadata = try!(fs::metadata(path));
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^ expected bool, found enum `std::result::Result`
    |
    = note: expected type `bool`
               found type `std::result::Result&lt;_, _&gt;`
    = note: this error originates in a macro outside of the current crate
  
  error[E0308]: mismatched types
   --&gt; src/main.rs:3:40
    |
  3 |   pub fn path_exists(path: &amp;str) -&gt; bool {
    |  ________________________________________^
  4 | |     let metadata = try!(fs::metadata(path));
  5 | |     assert!(metadata.is_file());
  6 | | }
    | |_^ expected (), found bool
    |
    = note: expected type `()`
               found type `bool`
  </code></pre>