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
mod from;
use crate::Command;
use std::fmt::{self, Debug, Display, Formatter};
#[derive(Clone,Eq, PartialEq)]
pub enum Value {
None,
String(String),
Integer(String),
Decimal(String),
Boolean(bool),
List(Vec<Value>),
Command(Command),
}
impl Value {
#[rustfmt::skip]
pub fn as_str(&self) -> &str {
match self {
Value::String(s) => s,
Value::Boolean(b) => {
if *b { "true" } else { "false" }
}
_ => unreachable!(),
}
}
pub fn trim(&self) -> &str {
match self {
Value::String(s) => s.trim(),
_ => self.as_str().trim(),
}
}
}
impl Debug for Value {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Value::None => write!(f, "none"),
Value::String(s) => write!(f, "{:?}", s),
Value::Integer(s) => write!(f, "{}", s),
Value::Decimal(s) => write!(f, "{}", s),
Value::Boolean(b) => write!(f, "{}", b),
Value::List(_) => unimplemented!(),
Value::Command(node) => write!(f, "{}", node),
}
}
}
impl Display for Value {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Value::None => write!(f, ""),
_ => write!(f, "{:?}", self),
}
}
}