rearrange code into iterator

This commit is contained in:
Quaternions 2024-01-24 21:10:13 -08:00
parent d5b8c10264
commit dfe899a7d8

View File

@ -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<String>={
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::<AResult<_>>()?
};
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{