use std::path::{Path, PathBuf};
use anyhow::{Context, Result};
use ignore::WalkBuilder;
pub(crate) fn collect_rust_files(root: &Path) -> Result<Vec<PathBuf>> {
if root.is_file() {
return Ok(vec![root.to_path_buf()]);
}
let mut files = Vec::new();
for entry in WalkBuilder::new(root).require_git(false).build() {
let entry = entry.with_context(|| format!("failed to walk {}", root.display()))?;
let path = entry.path();
let is_file = entry.file_type().is_some_and(|ft| ft.is_file());
if is_file && path.extension().is_some_and(|ext| ext == "rs") {
files.push(path.to_path_buf());
}
}
files.sort();
Ok(files)
}