diff --git a/src/config.rs b/src/config.rs index 4cac07a..4a15926 100644 --- a/src/config.rs +++ b/src/config.rs @@ -64,20 +64,18 @@ impl Config { if let Some(Value::Table(vars)) = self.inner.get("vars") { for (key, value) in vars.iter() { let key = key.to_owned(); - match value.clone() { - Value::Boolean(bool) => output.insert(key, bool.into()), - Value::Float(float) => output.insert(key, float.into()), - Value::Integer(int) => output.insert(key, int.into()), - Value::String(string) => output.insert(key, string.into()), - _ => None - }; + if let Some(value) = util::convert(value) { + output.insert(key, value); + } } } // pull target values for (key, value) in target.iter() { if key.to_uppercase() == *key { - output.insert(key.to_owned(), value.as_str().unwrap().into()); + if let Some(value) = util::convert(value) { + output.insert(key.to_owned(), value); + } } } diff --git a/src/util.rs b/src/util.rs index e7d36cc..33b3d59 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,5 @@ +use upon::Value as ContextValue; use toml::{ value::Array, Value }; pub fn matches(array: Array, to_match: String) -> Option { @@ -12,3 +13,13 @@ pub fn matches(array: Array, to_match: String) -> Option { }).map(|value| value.to_owned()).nth(0) } +pub fn convert(value: &Value) -> Option { + match value.clone() { + Value::Boolean(bool) => Some(bool.into()), + Value::Float(float) => Some(float.into()), + Value::Integer(int) => Some(int.into()), + Value::String(string) => Some(string.into()), + _ => None + } +} +