List and filter files in Rust
As far as I can tell, you're returning error only in case of read_dir failure. Not sure if anyone ever really needs it, but you could change upmost Some() to Ok(), remove .ok() and fix the signature so that my version works just like yours. Note: the code below wasn't tested. I didn't like nested structure of your function, so I came up with this:

use std::fs;
use std::path::PathBuf;

fn list_files(pathname: &amp;PathBuf, filter: &amp;str) -&gt; Option&lt;Vec&lt;PathBuf&gt;&gt; {
    Some(fs::read_dir(pathname).ok()?
        .filter_map(|entry| {
            Some(
                entry
                    .ok()?
                    .path()
                    .strip_prefix(pathname)
                    .ok()?
                    .to_path_buf(),
            )
        })
        .filter(|path| path.starts_with(filter))
        .collect())
}


Explanation: .ok() maps Result&lt;T, K&gt; to Option&lt;T&gt;, ? operator returns early in case if Option or Result aren't Some()/Ok()