mathml_rs/structs/
lambda.rs1use super::math_node::{MathNodeType, NodeIndex};
2use std::fmt;
3
4#[derive(Default, Debug, Clone)]
5pub struct Lambda {
6 pub children: Vec<NodeIndex>,
7 pub bindings: Vec<NodeIndex>,
8 pub expr: Option<NodeIndex>,
9 pub parent: Option<NodeIndex>,
10}
11
12impl Lambda {
13 pub fn index(&mut self, tag_type: MathNodeType, location: NodeIndex) {
14 match tag_type {
15 MathNodeType::Op
16 | MathNodeType::Apply
17 | MathNodeType::Lambda
18 | MathNodeType::Piecewise
19 | MathNodeType::Ci
20 | MathNodeType::Cn
21 | MathNodeType::Constant => {
22 if self.expr == None {
23 self.expr = Some(location);
24 } else {
25 panic!("Can't have two expressions in a lambda function!");
26 }
27 }
28 MathNodeType::BVar => {
29 self.bindings.push(location);
30 }
31 MathNodeType::Root | MathNodeType::Piece | MathNodeType::Otherwise => {
32 panic!("Can't have {} in a lambda function!", tag_type);
33 }
34 }
35 }
36}
37
38impl fmt::Display for Lambda {
39 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40 write!(
41 f,
42 "Bindings: {:?}, Expr: {:?}, Children: {:?}, Parent: {:?}",
43 self.bindings, self.expr, self.children, self.parent
44 )
45 }
46}