Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "choosing between walkdir and std::fs::read_dir" section to the docs #150

Open
matklad opened this issue Jul 3, 2021 · 0 comments
Open

Comments

@matklad
Copy link

matklad commented Jul 3, 2021

Meta: this isn't remotely important, logging the issue just for completeness sake.

In rust-analyzer, I am writing a test that needs to list all Rust files in rust-analyzer's repo. I think in this context using stdlib and doing something like the following should be fine:

fn list_files_recursively(dir: &Path) -> io::Result<Vec<PathBuf>> {
    let mut res = Vec::new();
    let mut work = vec![dir.to_path_buf()];
    while let Some(dir) = work.pop() {
        for entry in dir.read_dir()? {
            let entry = entry?;
            let file_type = entry.file_type()?;
            if file_type.is_dir() {
                work.push(entry.path())
            } else if file_type.is_file() {
                res.push(entry.path())
            }
        }
    }
    Ok(res)
}

However I am not sure -- there might be some pitfalls about std::fs::read_dir I am not sure about (similarly to how, eg, remove_dir_all doesn't always work on Windows). It would be helpful if walkdir (the primary alternative to "do it yourself") docs contained a section explaining when walkdir isn't actually needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant