rust_css_parser/parser/utils/
config.rs1use std::sync::OnceLock;
4
5pub static PROPERTIES_JSON: &str = include_str!("../../data/properties.json");
6
7pub fn get_config() -> &'static serde_json::Value {
9 static CONFIG: OnceLock<serde_json::Value> = OnceLock::new();
10 CONFIG.get_or_init(|| serde_json::from_str(PROPERTIES_JSON).expect("properties.json"))
11}
12
13pub struct ConfigIndex {
16 pub properties: crate::utils::fx::HashMap<&'static str, &'static serde_json::Value>,
17 pub map: crate::utils::fx::HashMap<&'static str, &'static serde_json::Value>,
18 pub property: crate::utils::fx::HashMap<&'static str, &'static serde_json::Value>,
19}
20
21pub static NULL: serde_json::Value = serde_json::Value::Null;
23
24impl ConfigIndex {
25 pub fn get(map: &crate::utils::fx::HashMap<&'static str, &'static serde_json::Value>, name: &str) -> &'static serde_json::Value {
27 map.get(name).copied().unwrap_or(&NULL)
28 }
29}
30
31pub fn config_index() -> &'static ConfigIndex {
33 static INDEX: OnceLock<ConfigIndex> = OnceLock::new();
34 INDEX.get_or_init(|| {
35 let config = get_config();
36 let group = |key: &str| {
37 config[key].as_object().map(|o| o.iter().map(|(k, v)| (k.as_str(), v)).collect()).unwrap_or_default()
38 };
39 ConfigIndex { properties: group("properties"), map: group("map"), property: group("property") }
40 })
41}