1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
pub type NodeIndex = usize; use crate::{ Apply, BVar, Ci, Cn, Constant, ConstantNode, Lambda, Op, OpNode, Otherwise, Piece, Piecewise, Root, }; use std::fmt; #[derive(Debug, Clone)] pub enum MathNode { Apply(Apply), Op(OpNode), Constant(ConstantNode), Root(Root), Ci(Ci), Cn(Cn), Lambda(Lambda), BVar(BVar), Piecewise(Piecewise), Piece(Piece), Otherwise(Otherwise), } impl MathNode { pub fn new_op(op: Op) -> Self { MathNode::Op(OpNode { op: Some(op), parent: None, }) } pub fn new_constant(constant: Constant) -> Self { MathNode::Constant(ConstantNode { constant: Some(constant), parent: None, }) } } impl Default for MathNode { fn default() -> Self { MathNode::Root(Root::default()) } } impl fmt::Display for MathNode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { MathNode::Apply(apply) => write!(f, "Apply: {}", apply), MathNode::Root(root) => write!(f, "Root: {}", root), MathNode::Ci(ci) => write!(f, "Ci: {}", ci), MathNode::Op(opnode) => write!(f, "Op: {}", opnode), MathNode::Cn(cn) => write!(f, "Cn: {}", cn), MathNode::Lambda(lambda) => write!(f, "Lambda: {}", lambda), MathNode::BVar(bvar) => write!(f, "BVar: {}", bvar), MathNode::Piecewise(piecewise) => write!(f, "Piecewise: {}", piecewise), MathNode::Piece(piece) => write!(f, "Piece: {}", piece), MathNode::Otherwise(otherwise) => write!(f, "Otherwise: {}", otherwise), MathNode::Constant(constantnode) => write!(f, "Constant: {}", constantnode), } } } pub enum MathNodeType { Apply, Op, Root, Ci, Cn, Lambda, BVar, Piecewise, Piece, Otherwise, Constant, } impl fmt::Display for MathNodeType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { MathNodeType::Apply => write!(f, "Apply"), MathNodeType::Root => write!(f, "Root"), MathNodeType::Ci => write!(f, "Ci"), MathNodeType::Op => write!(f, "Op"), MathNodeType::Constant => write!(f, "Constant"), MathNodeType::Cn => write!(f, "Cn"), MathNodeType::Lambda => write!(f, "Lambda"), MathNodeType::BVar => write!(f, "BVar"), MathNodeType::Piecewise => write!(f, "Piecewise"), MathNodeType::Piece => write!(f, "Piece"), MathNodeType::Otherwise => write!(f, "Otherwise"), } } }