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
use super::*;
use crate::schema::MessyJsonObjectTrait;
pub type KeyType = ArcStr;
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct MessyJsonObject(Arc<MessyJsonObjectInner>);
impl MessyJsonObject {
#[inline]
pub fn builder(&self, settings: MessyJsonSettings) -> MessyJsonObjectBuilder {
MessyJsonObjectBuilder::new(self, settings)
}
}
impl std::ops::Deref for MessyJsonObject {
type Target = MessyJsonObjectInner;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl From<MessyJsonObjectInner> for MessyJsonObject {
fn from(x: MessyJsonObjectInner) -> Self {
MessyJsonObject(Arc::new(x))
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
pub struct MessyJsonObjectInner {
optional: bool,
properties: BTreeMap<KeyType, MessyJson>,
}
impl MessyJsonObjectInner {
pub fn new(properties: BTreeMap<KeyType, MessyJson>, optional: bool) -> Self {
MessyJsonObjectInner {
properties: properties.into_iter().collect(),
optional,
}
}
#[inline]
pub fn properties(&self) -> &BTreeMap<KeyType, MessyJson> {
&self.properties
}
#[inline]
pub fn has_field(&self, key: &str) -> bool {
self.properties.contains_key(key)
}
#[inline]
pub fn optional(&self) -> bool {
self.optional
}
}
#[cfg(test)]
pub fn gen_key(k: &str) -> super::object::KeyType {
ArcStr::from(k)
}