A small helper function that returns a list of unique file names in a directory.
(path: &Path)
| 35 | |
| 36 | /// A small helper function that returns a list of unique file names in a directory. |
| 37 | pub fn filenames_in_dir(path: &Path) -> Result<HashSet<String>, Error> { |
| 38 | let entries = read_dir(path).map_err(|source| Error::IoPath { |
| 39 | path: path.to_path_buf(), |
| 40 | context: "retrieving the entries of the directory".to_string(), |
| 41 | source, |
| 42 | })?; |
| 43 | let mut files: HashSet<String> = HashSet::new(); |
| 44 | for entry in entries { |
| 45 | let entry = entry.map_err(|source| Error::IoPath { |
| 46 | path: path.to_path_buf(), |
| 47 | context: "retrieving an entry in the directory".to_string(), |
| 48 | source, |
| 49 | })?; |
| 50 | files.insert(entry.file_name().to_string_lossy().to_string()); |
| 51 | } |
| 52 | |
| 53 | Ok(files) |
| 54 | } |
no test coverage detected