colap 0.2.0

A lightweight, human-friendly configuration language parser & code generator
#[derive(Debug, Clone, Default)]
pub struct Api {
    pub key: Option<String>,
    pub base_url: Option<String>,
    pub type_: Option<String>,
}

impl Api {
    pub fn key(&self) -> Option<&String> {
        self.key.as_ref()
    }

    pub fn base_url(&self) -> Option<&String> {
        self.base_url.as_ref()
    }

    pub fn type_(&self) -> Option<&String> {
        self.type_.as_ref()
    }

}

impl Api {
    pub fn from_entity(model: &colap::model::config_model::ConfigModel, id: usize) -> Self {
        let mut result = Self::default();
        if let Some(node) = model.get_node(id) {
            let node_b = node.borrow();
            if let colap::model::config_model::ConfigNode::Entity(ent) = &*node_b {
                if let Some(val) = ent.fields.get("key") {
                    if let colap::model::config_model::ConfigValue::String(s) = val {
                        result.key = Some(s.clone());
                    }
                }
                if let Some(val) = ent.fields.get("base_url") {
                    if let colap::model::config_model::ConfigValue::String(s) = val {
                        result.base_url = Some(s.clone());
                    }
                }
                if let Some(val) = ent.fields.get("type") {
                    if let colap::model::config_model::ConfigValue::String(s) = val {
                        result.type_ = Some(s.clone());
                    }
                }
            }
        }
        result
    }
}