From 257b6144fa27c030a8eee45b8c832c769b9a1ffd Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 3 Mar 2024 23:40:54 +0100 Subject: 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. --- pkgs/profpatsch/nman/nman.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'pkgs/profpatsch/nman/nman.rs') 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, 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::>() { + // 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 -- cgit 1.4.1