use std::path::{Path, PathBuf};
use walkdir::WalkDir;
pub fn find_rs_files(root: &Path) -> anyhow::Result<Vec<PathBuf>> {
let mut out = Vec::new();
for entry in WalkDir::new(root)
.into_iter()
.filter_entry(|e| !is_skipped_descendant(root, e.path()))
{
let entry = entry?;
if entry.file_type().is_file()
&& entry.path().extension().map(|e| e == "rs").unwrap_or(false)
{
out.push(entry.into_path());
}
}
out.sort();
Ok(out)
}
fn is_skipped_descendant(root: &Path, p: &Path) -> bool {
if p == root {
return false;
}
let name = p.file_name().and_then(|s| s.to_str()).unwrap_or("");
if name == "target" {
return true;
}
p.is_dir() && name.starts_with('.')
}