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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use ordered_float::OrderedFloat;
pub mod convenience;
pub mod conversions;
pub use conversions::ConversionError;
pub mod dict;
pub use dict::{Dict, DictKey};
mod util {
#[cfg(target_pointer_width = "32")]
#[path = "small_boxed_slice_32bit.rs"]
pub mod small_boxed_slice;
#[cfg(target_pointer_width = "64")]
pub mod small_boxed_slice;
pub mod small_boxed_string;
pub mod trunc_8_bytes;
}
use util::small_boxed_slice::SmallBoxedSlice;
use util::small_boxed_string::SmallBoxedStr;
mod io {
pub mod read;
pub mod read_async;
pub mod write;
}
pub use io::read::ReadError;
pub mod json;
pub mod serde;
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(align(16))]
pub enum Litl {
String(SmallBoxedStr),
Number(OrderedFloat<f64>),
Array(SmallBoxedSlice<Litl>),
Dict(Dict),
Bool(bool),
Null,
TaggedData(TaggedData),
}
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
pub enum TaggedData {
Leaf (SmallBoxedSlice<u8>),
Nested {
tag: SmallBoxedStr,
inner: Box<Litl>,
},
}
#[rustfmt::skip]
#[allow(clippy::unusual_byte_groupings)]
mod consts {
pub const FALSE_VALUE: u8 = 0b_0000_0000; pub const TRUE_VALUE: u8 = 0b_0000_0001; pub const NULL_VALUE: u8 = 0b_0000_0010; pub const TAG_HEADER: u8 = 0b_0001_0000; pub const STR_HEADER: u8 = 0b_1000_0000; pub const NUM_HEADER: u8 = 0b_1001_0000; pub const ARR_HEADER: u8 = 0b_1010_0000; pub const DICT_HEADER: u8 = 0b_1011_0000; pub const HEADER_MASK: u8 = 0xF0;
}
#[cfg(test)]
mod tests {
use log::info;
use crate::Litl;
#[test]
fn sizes() {
info!("{}", std::mem::align_of::<Litl>());
info!("{}", std::mem::size_of::<Litl>());
}
}
#[macro_export]
macro_rules! impl_debug_as_litl {
($t:ty) => {
impl std::fmt::Debug for $t {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&litl::Litl::from_se(self), f)
}
}
};
}