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
use crate::{Blob, List, Map, MapKey, Object, ObjectKey, Value};
pub fn blob() -> Value {
Value::Blob(Blob::new())
}
pub fn blob_with_capacity(capacity: usize) -> Value {
Value::Blob(Blob::with_capacity(capacity))
}
pub fn list() -> Value {
Value::List(List::new())
}
pub fn list_with_capacity(capacity: usize) -> Value {
Value::List(List::with_capacity(capacity))
}
pub fn push<T>(list: &mut List, value: T) where T: Into<Value> {
list.push(value.into());
}
pub fn map() -> Value {
Value::Map(Map::new())
}
pub fn map_from<K, V>(key: K, value: V) -> Value where K: Into<MapKey>, V: Into<Value> {
let mut map = Map::new();
map_insert(&mut map, key, value);
map.into()
}
pub fn map_insert<K, V>(map: &mut Map, key: K, value: V) -> Option<Value> where K: Into<MapKey>, V: Into<Value> {
map.insert(key.into(), value.into())
}
pub fn object() -> Value {
Value::Object(Object::new())
}
pub fn object_from<K, V>(key: K, value: V) -> Value where K: Into<ObjectKey>, V: Into<Value> {
let mut object = Object::new();
object_insert(&mut object, key, value);
object.into()
}
pub fn object_insert<K, V>(object: &mut Object, key: K, value: V) -> Option<Value> where K: Into<ObjectKey>, V: Into<Value> {
object.insert(key.into(), value.into())
}