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
use crate::model::layer230::WS;
use crate::model::{
layer210::Comment,
layer225::Keyval,
layer230::{Expression, HeaderOfArrayOfTable, HeaderOfTable},
};
use std::fmt;
impl Expression {
pub fn from_header_of_array_of_table(m: &HeaderOfArrayOfTable) -> Self {
Expression::HeaderOfArrayOfTable(m.clone())
}
pub fn from_empty_line(ws: &WS, comment: &Comment) -> Self {
Expression::EmptyLine(ws.clone(), Some(comment.clone()))
}
pub fn from_keyval(ws1: &WS, keyval: &Keyval, ws2: &WS, comment: &Comment) -> Self {
Expression::Keyval(
ws1.clone(),
keyval.clone(),
ws2.clone(),
Some(comment.clone()),
)
}
pub fn from_header_of_table(m: &HeaderOfTable) -> Self {
Expression::HeaderOfTable(m.clone())
}
pub fn to_debug_string(&self) -> String {
format!("{:?}", self)
}
pub fn to_string(&self) -> String {
format!("{}", self)
}
}
impl fmt::Display for Expression {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expression::HeaderOfArrayOfTable(m) => write!(f, "{}", m),
Expression::EmptyLine(ws, comment) => write!(
f,
"{}{}",
ws,
if let Some(comment) = comment {
comment.to_string()
} else {
"".to_string()
}
),
Expression::Keyval(ws1, keyval, ws2, comment) => write!(
f,
"{}{}{}{}",
ws1,
keyval,
ws2,
if let Some(comment) = comment {
comment.to_string()
} else {
"".to_string()
}
),
Expression::HeaderOfTable(m) => write!(f, "{}", m),
}
}
}
impl fmt::Debug for Expression {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expression::HeaderOfArrayOfTable(m) => write!(f, "{:?}", m),
Expression::EmptyLine(ws, comment) => write!(f, "{:?}{:?}", ws, comment),
Expression::Keyval(ws1, keyval, ws2, comment) => {
write!(f, "{:?}{:?}{:?}{:?}", ws1, keyval, ws2, comment)
}
Expression::HeaderOfTable(m) => write!(f, "{:?}", m),
}
}
}