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
use std::collections::BTreeMap;
use std::ops::Index;
pub trait Deserializer<D>: Index<String>
where
D: Deserializer<D>,
{
fn get_field(&self, key: &str) -> Option<&D>;
fn get_type(&self) -> Option<String>;
fn as_map(&self) -> Option<BTreeMap<String, &D>>;
fn as_vec(&self) -> Option<Vec<&D>>;
fn as_str(&self) -> Option<&str>;
}
impl<D> Index<String> for &dyn Deserializer<D, Output = D>
where
D: Deserializer<D> + Index<String>,
<D as Index<String>>::Output: Deserializer<D> + Index<String>,
{
type Output = D;
fn index(&self, index: String) -> &Self::Output {
self.get_field(index.as_ref()).unwrap()
}
}