config_more_formats/
hjson.rs

1use crate::util::{extract_root_table, from_value, Val};
2use config::{FileStoredFormat, Format, Map, Value};
3use std::error::Error;
4
5#[derive(Debug)]
6pub struct Hjson;
7
8impl Format for Hjson {
9    fn parse(&self, uri: Option<&String>, text: &str) -> Result<Map<String, Value>, Box<dyn Error + Send + Sync>> {
10        let hjson: Val = serde_hjson::from_str(text).map_err(|err| Box::new(err) as Box<dyn Error + Send + Sync>)?;
11
12        extract_root_table(from_value(uri, hjson))
13    }
14}
15
16static EXTENSIONS: [&str; 1] = ["hjson"];
17
18impl FileStoredFormat for Hjson {
19    fn file_extensions(&self) -> &'static [&'static str] {
20        &EXTENSIONS
21    }
22}