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
|
use std::fmt;
#[derive(Clone)]
pub enum Value {
Literal(i64),
Pair(Box<Pair>),
}
#[derive(Clone)]
pub struct Pair {
pub left: Value,
pub right: Value,
}
impl fmt::Debug for Value {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Value::Literal(n) => { write!(formatter, "{}", n) }
Value::Pair(pair) => { write!(formatter, "{:?}", pair) }
}
}
}
impl fmt::Debug for Pair {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "[{:?},{:?}]", self.left, self.right)
}
}
|