Iterate over all of the files passed as arguments, recursively iterating through directories.
(files: &'a [PathBuf])
| 26 | |
| 27 | /// Iterate over all of the files passed as arguments, recursively iterating through directories. |
| 28 | pub fn iterate_files<'a>(files: &'a [PathBuf]) -> impl Iterator<Item = PathBuf> + 'a { |
| 29 | files |
| 30 | .iter() |
| 31 | .flat_map(WalkDir::new) |
| 32 | .filter(|f| match f { |
| 33 | Ok(d) => { |
| 34 | // Filter out hidden files (starting with .). |
| 35 | !d.file_name().to_str().map_or(false, |s| s.starts_with('.')) |
| 36 | // Filter out directories. |
| 37 | && !d.file_type().is_dir() |
| 38 | } |
| 39 | Err(e) => { |
| 40 | println!("Unable to read file: {e}"); |
| 41 | false |
| 42 | } |
| 43 | }) |
| 44 | .map(|f| { |
| 45 | f.expect("this should not happen: we have already filtered out the errors") |
| 46 | .into_path() |
| 47 | }) |
| 48 | } |