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
pub use defaults::Defaults;
pub use serde::{de, Deserialize, Deserializer, Serialize};
pub use serde_json::Value;
pub use serde_with::skip_serializing_none;
use std::collections::BTreeMap;
pub use std::sync::Arc;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Primitive {
Null,
Bool(Bool),
Integer(Integer),
Number(Number),
String(String),
Object(Object),
Array(Array),
}
pub type Bool = bool;
pub type Integer = i64;
pub type Number = f64;
pub type Array = Vec<Primitive>;
pub type Object = BTreeMap<String, Primitive>;
#[macro_export]
macro_rules! impl_type {
($type:ident) => {
impl $type {
pub fn deserialize_type<'de, D>(d: D) -> Result<String, D::Error>
where
D: Deserializer<'de>,
{
let value = String::deserialize(d)?;
if value != stringify!($type) {
return Err(de::Error::invalid_value(
de::Unexpected::Str(value.as_str()),
&stringify!($type),
));
}
Ok(value)
}
}
};
}