about summary refs log tree commit diff
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2024-03-03 23:40:54 +0100
committerProfpatsch <mail@profpatsch.de>2024-03-03 23:43:30 +0100
commit257b6144fa27c030a8eee45b8c832c769b9a1ffd (patch)
treece65230185a9bdce7f1b4b221635ceda362b1dd6
parenta8860bdd8e1beac39c755fe40f61a883b7407c7c (diff)
pkgs/profpatsch/nman: rewrite directory iteration to more imperative
This is gonna make it a lot easier to enumerate the manpages as well.
Plus the code gets somewhat easier to read in my opinion.
-rw-r--r--pkgs/profpatsch/nman/nman.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/pkgs/profpatsch/nman/nman.rs b/pkgs/profpatsch/nman/nman.rs
index 9ce43c58..b9961f1e 100644
--- a/pkgs/profpatsch/nman/nman.rs
+++ b/pkgs/profpatsch/nman/nman.rs
@@ -447,28 +447,28 @@ impl Main {
     }
 
     fn enumerate_man_pages<'a>(path: &PathBuf) -> Result<Vec<FoundManSection>, NmanError<'a>> {
-        Ok(read_dir(path.as_path())
-            .map_err(NmanError::IO)?
-            .filter_map(|entry| {
-                // ignore directories/files that cannot be read
-                let e = entry.ok()?;
-                e.file_name()
+        let dirs = read_dir(path.as_path()).map_err(NmanError::IO)?;
+        let mut res = Vec::new();
+        for entry in dirs.collect::<Vec<_>>() {
+            // ignore directories/files that cannot be read
+            if let Ok(e) = entry {
+                // separate "man" prefix from section indicator,
+                // while validating the particular sub directory
+                if let Some((prefix, man_section)) = e
+                    .file_name()
                     .to_str()
-                    // separate "man" prefix from section indicator,
-                    // while validating the particular sub directory
                     .filter(|d| d.len() > 3)
                     .map(|d| d.split_at(3))
-                    .and_then(|(prefix, man_section)| {
-                        if prefix == "man" {
-                            Some(FoundManSection {
-                                man_section: String::from(man_section),
-                            })
-                        } else {
-                            None
-                        }
-                    })
-            })
-            .collect())
+                {
+                    if prefix == "man" {
+                        res.push(FoundManSection {
+                            man_section: String::from(man_section),
+                        })
+                    }
+                }
+            }
+        }
+        Ok(res)
     }
 
     /// Realises the given derivation output using `nix-store --realise` and