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
use crate::*;
#[derive(Clone, Hash, PartialEq, Eq, Debug)]
/// Generic value.
pub enum Value {
Int(i64),
String(LString),
Binary(LVec<u8>),
List(LVec<Value>),
Enum(i64, LBox<Value>),
VarVal(u64, u64),
IList(LVec<i64>),
}
impl Value {
// Get mut reference to List LVec ( Value must be List )
pub fn list(&mut self) -> &mut LVec<Value> {
match self {
Value::List(list) => list,
_ => panic!(),
}
}
// Get mut reference to IList LVec ( Value must be IList )
pub fn ilist(&mut self) -> &mut LVec<i64> {
match self {
Value::IList(list) => list,
_ => panic!(),
}
}
// Get reference to LString ( Value must be String )
pub fn string(&self) -> &LString {
match self {
Value::String(s) => s,
_ => panic!(),
}
}
pub fn int(&self) -> i64 {
match self {
Value::Int(x) => *x,
_ => panic!(),
}
}
}
#[test]
fn test_value() {
/*
use pstd::veca;
let v1 = Value::List(veca![
Value::String(LString::from("George Barwood")),
Value::String(LString::from("george.barwood@gmail.com")),
Value::String(LString::from("33 Sandpipe Close, GL2 4LZ")),
Value::Int(-47),
Value::Int(99),
Value::VarVal(100, 20),
Value::IList(veca![1, 2, 3, 4]),
]);
let bytes = v1.to_bytes();
println!("len={} bytes={:?}", bytes.len(), bytes);
let v2 = Value::from_bytes(&bytes);
println!("v2={:?}", v2);
*/
}