local_fmt_macros_internal/def_local_fmt/internal/file/
json.rs

1use super::MessageLoader;
2
3pub struct JsonMessageLoader;
4
5impl MessageLoader for JsonMessageLoader {
6    const EXTENSION: &'static str = "json";
7
8    type Value = serde_json::Value;
9    type NestValue = serde_json::Map<String, serde_json::Value>;
10    const NEST_VALUE_NAME: &'static str = "object";
11
12    fn value_to_nest(value: Self::Value) -> Option<Self::NestValue> {
13        match value {
14            serde_json::Value::Object(s) => Some(s),
15            _ => None,
16        }
17    }
18
19    fn value_as_str(value: &Self::Value) -> Option<&str> {
20        value.as_str()
21    }
22
23    fn value_from_str(content: &str) -> Result<Self::Value, String> {
24        serde_json::from_str(content).map_err(|e| e.to_string())
25    }
26
27    fn iter_nested(value: Self::NestValue) -> impl Iterator<Item = (String, Self::Value)> {
28        value.into_iter()
29    }
30}