jweinst1
4/5/2017 - 5:52 PM

ast system in rust

ast system in rust

use std::fmt;

#[derive(Debug)]
pub enum ASTNode {
	Leaf{key:String, val:String},
	Branch{key:String, children:Vec<ASTNode>}
}

impl fmt::Display for ASTNode {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
        	ASTNode::Leaf{ref key, ref val} => write!(f, "({}, {})", key, val),
        	ASTNode::Branch{ref key, ref children} => write!(f, "({}, {:?})", key, children)
        }
        
    }
}

fn main(){
    println!("{}", ASTNode::Branch{key:"h".to_string(), children:vec![ASTNode::Leaf{key:"f".to_string(), val:"42".to_string()}]});
}