nb-tree 0.2.0-alpha01

Very simple tree structure with generic node and branch data.
Documentation
use crate::prelude::{Entry, Path, Tree};

use super::{depth::Traversal, TraversalNode};

pub struct Combine<I, R, N, B, const BOUND: bool>
where
    R: Deref<Target = Tree<N, B>>,
{
    iter: I,
    other: Entry<R, N, B, BOUND>,
}

impl<I, R, N, B, const BOUND: bool> Combine<I, R, N, B, BOUND>
where
    I: Iterator,
    R: Deref<Target = Tree<N, B>>,
{
    pub fn new(iter: I, other: Entry<R, N, B, BOUND>) -> Combine<I, R, N, B, BOUND> {
        Combine { iter, other }
    }
}

impl<I, NI, R, N, B, const BOUND: bool> Iterator for Combine<I, R, N, B, BOUND>
where
    I: Iterator<Item = Traversal<NI, B>>,
    R: Deref<Target = Tree<N, B>>,
    B: Clone,
{
    type Item = TraversalNode<(Option<N1>, Option<N2>), B>;

    fn next(&mut self) -> Option<Self::Item> {
        //        todo!();
        //        if let Some(last) = self.children.last_mut() {
            // Iterate on a child (not the root)
            if let Some((branch, node_idx)) = last.next() {
                // Go down to a child
                let node = &self.tree.nodes[*node_idx];
                self.children.push(node.children.iter());
                //self.path.push_leaf(branch.clone());
                Some(Traversal::Step {
                    up: std::mem::replace(&mut self.up, 0),
                    branch,
                    data: T::target(self.tree, *node_idx),
                })
                //Some((self.path.clone(), &node.value))
            } else {
                // Move back up to the parent
                self.children.pop();
                //self.path.pop_leaf();
                self.up += 1;
                self.next()
            }
        } else if let Some(root) = self.root.take() {
            let node = &self.tree.nodes[root];
            self.children.push(node.children.iter());
            Some(Traversal::Start(T::target(self.tree, root)))
        } else {
            None
        }
    }
}