local_fmt_macros_internal/def_local_fmt/internal/file/
toml.rs

1use super::MessageLoader;
2
3pub struct TomlMessageLoader;
4
5impl MessageLoader for TomlMessageLoader {
6    const EXTENSION: &'static str = "toml";
7
8    type Value = toml::Value;
9    type NestValue = toml::Table;
10    const NEST_VALUE_NAME: &'static str = "table";
11
12    fn value_to_nest(value: Self::Value) -> Option<Self::NestValue> {
13        match value {
14            toml::Value::Table(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        toml::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}