title: Filtering files or directories discovered with fs::read_dir()
body: <p>I've got this function:</p>
  
  <pre><code>fn folders(dir: &amp;Path) -&gt; Result&lt;Vec&lt;PathBuf&gt;, io::Error&gt; {
      fs::read_dir(dir)?
          .into_iter()
          .map(|x| x.map(|entry| entry.path()))
          .collect()
  }
  </code></pre>
  
  <p>It's actually borrowed from <a href="https://stackoverflow.com/questions/37439327/how-to-write-a-function-that-returns-vecpath">here</a>. The function is OK; unfortunately, I don't really understand how it works.</p>
  
  <pre><code>Ok(["/home/ey/dir-src/9", "/home/ey/dir-src/11", "/home/ey/dir-src/03 A Letter of Explanation.mp3", "/home/ey/dir-src/02 Egyptian Avenue.mp3", "/home/ey/dir-src/alfa", "/home/ey/dir-src/10"])
  </code></pre>
  
  <p>The test output shows both directories and files, just as it should. I can't figure out where to put filtering for files/directories. I don't understand why the mapping inside mapping: isn't it just a simple list of paths? What is really happening inside this expression?</p>
  
  <p>UPD:</p>
  
  <pre><code>fn folders(dir: &amp;Path) -&gt; Result&lt;Vec&lt;PathBuf&gt;, io::Error&gt; {
      fs::read_dir(dir)?
          .into_iter()
          .map(|x| x.map(|entry| entry.path()))
          .filter(|x| {x.as_ref().map(|entry| entry); true})
          .collect()
  }
  </code></pre>
  
  <p>A trivial filter (always <code>true</code>) inserted. It is compiling at least, but I still can't see how am I supposed to use <code>entry</code> for file/directory checking. Sorry :)</p>