Skip to content

Commit

Permalink
docs: add docstring for collect_files_with_extension (#1712)
Browse files Browse the repository at this point in the history
During working on #1711 I accidentally went over this method in terms of
docs.
Thought this might help future devs anyhow

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
CommanderStorm and pre-commit-ci[bot] authored Mar 2, 2025
1 parent cd299d7 commit 944313c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions martin/src/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ async fn resolve_int<T: SourceConfigExtras>(
let dir_files = if is_dir {
// directories will be kept in the config just in case there are new files
directories.push(path.clone());
dir_to_paths(&path, extension)?
collect_files_with_extension(&path, extension)?
} else if path.is_file() {
vec![path]
} else {
Expand Down Expand Up @@ -341,16 +341,24 @@ async fn resolve_int<T: SourceConfigExtras>(
Ok(results)
}

fn dir_to_paths(path: &Path, extension: &[&str]) -> Result<Vec<PathBuf>, FileError> {
Ok(path
/// Returns a vector of file paths matching any `allowed_extension` within the given directory.
///
/// # Errors
///
/// Returns an error if Rust's underlying [`read_dir`](std::fs::read_dir) returns an error.
fn collect_files_with_extension(
base_path: &Path,
allowed_extension: &[&str],
) -> Result<Vec<PathBuf>, FileError> {
Ok(base_path
.read_dir()
.map_err(|e| IoError(e, path.to_path_buf()))?
.map_err(|e| IoError(e, base_path.to_path_buf()))?
.filter_map(Result::ok)
.filter(|f| {
f.path()
.extension()
.filter(|actual_ext| {
extension
allowed_extension
.iter()
.any(|expected_ext| expected_ext == actual_ext)
})
Expand Down

0 comments on commit 944313c

Please sign in to comment.