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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use Encode;
use IndexMap;
use HashMap;
use BTreeMap;
/// Encode Object
///
/// ```
/// use encoder::json::Encode;
/// use indexmap::IndexMap;
/// use std::collections::HashMap;
/// use std::collections::BTreeMap;
///
/// {
/// let mut buf = vec![];
/// let mut map = HashMap::new();
/// map.insert("hello", "world\n");
/// map.insert("aloha", "honua\n");
/// map.encode(&mut buf);
/// assert_eq!(unsafe { simd_json::from_str::<HashMap<&str, &str>>(map.stringify().as_mut_str()).unwrap() }, map);
/// assert_eq!(simd_json::from_slice::<HashMap<&str, &str>>(buf.as_mut_slice()).unwrap(), map);
/// }
///
/// {
/// let mut buf = vec![];
/// let mut map = HashMap::new();
/// map.insert(123, "world\n");
/// map.insert(456, "honua\n");
/// map.encode(&mut buf);
/// assert_eq!(unsafe { simd_json::from_str::<HashMap<i32, &str>>(map.stringify().as_mut_str()).unwrap() }, map);
/// assert_eq!(simd_json::from_slice::<HashMap<i32, &str>>(buf.as_mut_slice()).unwrap(), map);
/// }
///
/// {
/// let mut buf = vec![];
/// let mut map = BTreeMap::new();
/// map.insert("hello", "world\n");
/// map.insert("aloha", "honua\n");
/// map.encode(&mut buf);
/// assert_eq!(map.stringify(), r#"{"aloha":"honua\n","hello":"world\n"}"#);
/// assert_eq!(String::from_utf8_lossy(&buf), r#"{"aloha":"honua\n","hello":"world\n"}"#);
/// }
///
/// {
/// let mut buf = vec![];
/// let mut map = IndexMap::new();
/// map.insert("aloha", "honua\n");
/// map.insert("hello", "world\n");
/// map.encode(&mut buf);
/// assert_eq!(map.stringify(), r#"{"aloha":"honua\n","hello":"world\n"}"#);
/// assert_eq!(String::from_utf8_lossy(&buf), r#"{"aloha":"honua\n","hello":"world\n"}"#);
/// }
///
/// {
/// let mut buf = vec![];
/// let mut map: IndexMap<&str, &dyn Encode> = IndexMap::new();
/// map.insert("string", &"world");
/// map.insert("number", &12345);
/// map.encode(&mut buf);
/// assert_eq!(map.stringify(), r#"{"string":"world","number":12345}"#);
/// assert_eq!(String::from_utf8_lossy(&buf), r#"{"string":"world","number":12345}"#);
/// }
/// ```
impl_object!;
impl_object!;
impl_object!;