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
use crate::{
defpart,
pretty::{
containers::{Dictionary, List, Map},
iterator::{MapIterator, PartIterator},
nesting::Wrapped,
part::Part,
part_trait::PartTrait,
scalars::{DebugText, Opaque, Text},
sigils::StdWrappers,
},
};
defpart! {
for tycho::Element;
impl Part(|part, element| match element {
tycho::Element::Unit => part + "unit",
tycho::Element::Value(value) => part + value,
tycho::Element::Option(option) => match option {
Some(element) => part + element,
None => part + "None",
},
tycho::Element::Variant(tag, element) => {
part + tag + Wrapped(StdWrappers::Parens, element)
}
tycho::Element::Struct(s) => part + Dictionary(MapIterator(s.into_iter())),
tycho::Element::List(list) => part + List(PartIterator(list)),
tycho::Element::Array(_id, _list) => todo!("Element::Array"),
tycho::Element::Map(_id, map) => part + Map(MapIterator(map.into_iter())),
tycho::Element::Compression(_) => todo!("Element::Compression"),
})
}
impl PartTrait for Box<tycho::Element> {
fn append_to(self, builder: Part) -> Part {
(*self).append_to(builder)
}
}
impl PartTrait for tycho::Value {
fn append_to(self, left: Part) -> Part {
match self {
tycho::Value::Null => left + "null",
tycho::Value::Boolean(bool) => left + Text(bool),
tycho::Value::String(string) => left + DebugText(string),
tycho::Value::Char(char) => left + DebugText(char),
tycho::Value::Number(num) => left + Text(num),
tycho::Value::Bytes(_bytes) => {
left + Opaque("bytes")
}
tycho::Value::UUID(uuid) => left + Text(uuid),
}
}
}