From dfe899a7d8e60906d96fc89948b6a27d1cf84c65 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 24 Jan 2024 21:10:13 -0800 Subject: [PATCH] rearrange code into iterator --- src/main.rs | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 66f490e..9487042 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1491,18 +1491,19 @@ async fn compile(config:CompileConfig)->AResult<()>{ stack.push(CompileStackInstruction::PopFolder); //check if a folder exists with item.name if let Ok(mut dir)=tokio::fs::read_dir(folder.as_path()).await{ - let mut exist_names=std::collections::HashSet::new(); + let mut exist_names:std::collections::HashSet={ + let item=dom.get_by_ref(item_ref).ok_or(anyhow::Error::msg("null child ref"))?; + //push existing dom children objects onto stack (unrelated to exist_names) + stack.extend(item.children().into_iter().map(|&referent|CompileStackInstruction::TraverseReferent(referent,None))); + //get names of existing objects + item.children().into_iter().map(|&child_ref|{ + let child=dom.get_by_ref(child_ref).ok_or(anyhow::Error::msg("null child ref"))?; + Ok::<_,anyhow::Error>(sanitize(child.name.as_str()).to_string()) + }).collect::>()? + }; if let Some(dont)=blacklist{ exist_names.insert(dont); } - { - let item=dom.get_by_ref(item_ref).ok_or(anyhow::Error::msg("null child ref"))?; - for &child_ref in item.children(){ - let child=dom.get_by_ref(child_ref).ok_or(anyhow::Error::msg("null child ref"))?; - let child_sans=sanitize(child.name.as_str()).to_string(); - exist_names.insert(child_sans); - } - } //generate children from folder contents UNLESS! item already has a child of the same name let mut join_set=tokio::task::JoinSet::new(); //I wish I could make the join_next() loop begin processing immediately, @@ -1532,11 +1533,6 @@ async fn compile(config:CompileConfig)->AResult<()>{ }); } } - //push existing dom children objects onto stack - { - let item=dom.get_by_ref(item_ref).ok_or(anyhow::Error::msg("null child ref"))?; - stack.extend(item.children().into_iter().map(|&referent|CompileStackInstruction::TraverseReferent(referent,None))) - }; //push child objects onto dom //this is only able to begin after dir iterator is exhausted while let Some(goober)=join_set.join_next().await{