From 944313c85ae00091234974ee33a3f1f833815dd7 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sun, 2 Mar 2025 23:06:03 +0100 Subject: [PATCH] docs: add docstring for `collect_files_with_extension` (#1712) 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> --- martin/src/file_config.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/martin/src/file_config.rs b/martin/src/file_config.rs index 56a1062af..227f84648 100644 --- a/martin/src/file_config.rs +++ b/martin/src/file_config.rs @@ -309,7 +309,7 @@ async fn resolve_int( 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 { @@ -341,16 +341,24 @@ async fn resolve_int( Ok(results) } -fn dir_to_paths(path: &Path, extension: &[&str]) -> Result, 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, 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) })