use std::sync::OnceLock;
pub static PROPERTIES_JSON: &str = include_str!("../../data/properties.json");
pub fn get_config() -> &'static serde_json::Value {
static CONFIG: OnceLock<serde_json::Value> = OnceLock::new();
CONFIG.get_or_init(|| serde_json::from_str(PROPERTIES_JSON).expect("properties.json"))
}
pub struct ConfigIndex {
pub properties: crate::utils::fx::HashMap<&'static str, &'static serde_json::Value>,
pub map: crate::utils::fx::HashMap<&'static str, &'static serde_json::Value>,
pub property: crate::utils::fx::HashMap<&'static str, &'static serde_json::Value>,
}
pub static NULL: serde_json::Value = serde_json::Value::Null;
impl ConfigIndex {
pub fn get(map: &crate::utils::fx::HashMap<&'static str, &'static serde_json::Value>, name: &str) -> &'static serde_json::Value {
map.get(name).copied().unwrap_or(&NULL)
}
}
pub fn config_index() -> &'static ConfigIndex {
static INDEX: OnceLock<ConfigIndex> = OnceLock::new();
INDEX.get_or_init(|| {
let config = get_config();
let group = |key: &str| {
config[key].as_object().map(|o| o.iter().map(|(k, v)| (k.as_str(), v)).collect()).unwrap_or_default()
};
ConfigIndex { properties: group("properties"), map: group("map"), property: group("property") }
})
}