fn parse_json_config_spec(
    config_spec: &JsonProductConfigSpecProperties,
    property_spec: &[PropertySpec],
) -> Result<ProductConfigSpec, Error> {
    // pack unit name and compiled regex pattern into map
    let mut config_spec_units = HashMap::new();
    for unit in &config_spec.units {
        let unit_name = if unit.name.is_empty() {
            return Err(Error::ConfigSpecPropertiesNotFound {
                name: "unit".to_string(),
            });
        } else {
            unit.name.clone()
        };

        // no regex or empty regex provided
        let unit_regex = if unit.regex.is_none() || unit.regex == Some("".to_string()) {
            return Err(Error::EmptyRegexPattern {
                unit: unit.name.clone(),
            });
        } else {
            unit.regex.clone().unwrap()
        };

        let regex = match Regex::new(unit_regex.as_str()) {
            Ok(regex) => regex,
            Err(_) => {
                return Err(Error::InvalidRegexPattern {
                    unit: unit_name,
                    regex: unit_regex,
                });
            }
        };

        config_spec_units.insert(unit_name, regex);
    }

    // pack properties via name into hashmap for easier access
    let mut parsed_property_spec = HashMap::new();
    for property in property_spec {
        // for every provided property name, write property name and spec into map
        for property_name in &property.property_names {
            parsed_property_spec.insert(property_name.clone(), property.clone());
        }
    }

    Ok(ProductConfigSpec {
        config_spec: ProductConfigSpecProperties {
            units: config_spec_units,
        },
        property_specs: parsed_property_spec,
    })
}
/// Parse the provided config spec. Store the property spec in a hashmap with the property name
/// as key and spec as value. Parse any additional settings like units and the respective regex patterns.
///
/// # Arguments
///
/// * `config_spec` - the config spec provided by the JsonConfigReader
/// * `property_spec` - the property spec provided by the JsonConfigReader
///
Parse the provided config spec. Store the property spec in a hashmap with the property name
as key and spec as value. Parse any additional settings like units and the respective regex patterns.
Parse the provided config spec . Store the property spec in a hashmap with the property name as key and spec as value . Parse any additional settings like units and the respective regex patterns .
fn parse_json_config_spec(
    config_spec: &JsonProductConfigSpecProperties,
    property_spec: &[PropertySpec],
) -> Result<ProductConfigSpec, Error> {
    // pack unit name and compiled regex pattern into map
    let mut config_spec_units = HashMap::new();
    for unit in &config_spec.units {
        let unit_name = if unit.name.is_empty() {
            return Err(Error::ConfigSpecPropertiesNotFound {
                name: "unit".to_string(),
            });
        } else {
            unit.name.clone()
        };
        // no regex or empty regex provided
        let unit_regex = if unit.regex.is_none() || unit.regex == Some("".to_string()) {
            return Err(Error::EmptyRegexPattern {
                unit: unit.name.clone(),
            });
        } else {
            unit.regex.clone().unwrap()
        };
        let regex = match Regex::new(unit_regex.as_str()) {
            Ok(regex) => regex,
            Err(_) => {
                return Err(Error::InvalidRegexPattern {
                    unit: unit_name,
                    regex: unit_regex,
                });
            }
        };
        config_spec_units.insert(unit_name, regex);
    }
    // pack properties via name into hashmap for easier access
    let mut parsed_property_spec = HashMap::new();
    for property in property_spec {
        // for every provided property name, write property name and spec into map
        for property_name in &property.property_names {
            parsed_property_spec.insert(property_name.clone(), property.clone());
        }
    }
    Ok(ProductConfigSpec {
        config_spec: ProductConfigSpecProperties {
            units: config_spec_units,
        },
        property_specs: parsed_property_spec,
    })
}
fn parse_json_config_spec ( config_spec : & JsonProductConfigSpecProperties , property_spec : & [ PropertySpec ] , ) -> Result < ProductConfigSpec , Error > { // pack unit name and compiled regex pattern into map let mut config_spec_units = HashMap :: new ( ) ; for unit in & config_spec . units { let unit_name = if unit . name . is_empty ( ) { return Err ( Error :: ConfigSpecPropertiesNotFound { name : " " . to_string ( ) , } ) ; } else { unit . name . clone ( ) } ; // no regex or empty regex provided let unit_regex = if unit . regex . is_none ( ) || unit . regex == Some ( " " . to_string ( ) ) { return Err ( Error :: EmptyRegexPattern { unit : unit . name . clone ( ) , } ) ; } else { unit . regex . clone ( ) . unwrap ( ) } ; let regex = match Regex :: new ( unit_regex . as_str ( ) ) { Ok ( regex ) => regex , Err ( _ ) => { return Err ( Error :: InvalidRegexPattern { unit : unit_name , regex : unit_regex , } ) ; } } ; config_spec_units . insert ( unit_name , regex ) ; } // pack properties via name into hashmap for easier access let mut parsed_property_spec = HashMap :: new ( ) ; for property in property_spec { // for every provided property name, write property name and spec into map for property_name in & property . property_names { parsed_property_spec . insert ( property_name . clone ( ) , property . clone ( ) ) ; } } Ok ( ProductConfigSpec { config_spec : ProductConfigSpecProperties { units : config_spec_units , } , property_specs : parsed_property_spec , } ) }
Parse the provided config spec.
Parse the provided config spec .
config_spec
&JsonProductConfigSpecProperties
property_spec
&[PropertySpec]