use crate::model::{Chapter, NodeId};
pub fn walk_bottom_up<F>(chapter: &mut Chapter, mut visitor: F)
where
F: FnMut(&mut Chapter, NodeId),
{
if chapter.node_count() > 0 {
walk_children(chapter, NodeId::ROOT, &mut visitor);
}
}
fn walk_children<F>(chapter: &mut Chapter, parent_id: NodeId, visitor: &mut F)
where
F: FnMut(&mut Chapter, NodeId),
{
let mut child_opt = chapter.node(parent_id).and_then(|n| n.first_child);
while let Some(child_id) = child_opt {
walk_children(chapter, child_id, visitor);
child_opt = chapter.node(child_id).and_then(|n| n.next_sibling);
}
visitor(chapter, parent_id);
}