/// Convert an intermediary `TreeValue` to the public `Tree` type
Convert an intermediary `TreeValue` to the public `Tree` type
Convert an intermediary ` TreeValue ` to the public ` Tree ` type
fn newick_to_graph(root: TreeValue) -> Result<Tree> {
    fn add_node(g: &mut TreeGraph, t: TreeValue) -> NodeIndex {
        match t {
            TreeValue::Node { name, children } => {
                let node_id = g.add_node(name.unwrap_or("N/A".into()).into());
                if let Some(children) = children {
                    for child in children {
                        match child {
                            TreeValue::Node { .. } => unimplemented!(),
                            TreeValue::Link { weight, node } => {
                                let child_id = add_node(g, *node);
                                g.add_edge(node_id, child_id, weight);
                            }
                        }
                    }
                };
                node_id
            }
            TreeValue::Link { .. } => unreachable!(),
        }
    }
    let mut g = TreeGraph::new();
    add_node(&mut g, root);
    Ok(Tree { g })
}
fn newick_to_graph ( root : TreeValue ) -> Result < Tree > { fn add_node ( g : & mut TreeGraph , t : TreeValue ) -> NodeIndex { match t { TreeValue :: Node { name , children } => { let node_id = g . add_node ( name . unwrap_or ( " " . into ( ) ) . into ( ) ) ; if let Some ( children ) = children { for child in children { match child { TreeValue :: Node { .. } => unimplemented ! ( ) , TreeValue :: Link { weight , node } => { let child_id = add_node ( g , * node ) ; g . add_edge ( node_id , child_id , weight ) ; } } } } ; node_id } TreeValue :: Link { .. } => unreachable ! ( ) , } } let mut g = TreeGraph :: new ( ) ; add_node ( & mut g , root ) ; Ok ( Tree { g } ) }
Convert an intermediary `TreeValue` to the public `Tree` type
Convert an intermediary ` TreeValue ` to the public ` Tree ` type
root
TreeValue