add method to get vec from config

This commit is contained in:
Adrian Malacoda 2018-05-12 00:41:04 -05:00
parent 4bfe6e2aec
commit 9052a3b26b

View File

@ -1,11 +1,18 @@
use toml;
use toml::value::Table; use toml::value::Table;
pub trait Config { pub trait Config {
fn get_string (&self, key: &str) -> Option<&str>; fn get_string (&self, key: &str) -> Option<&str>;
fn get_vec (&self, key: &str) -> Option<Vec<toml::Value>>;
} }
impl Config for Table { impl Config for Table {
fn get_string (&self, key: &str) -> Option<&str> { fn get_string (&self, key: &str) -> Option<&str> {
self.get(key).and_then(|value| value.as_str()) self.get(key).and_then(|value| value.as_str())
} }
fn get_vec (&self, key: &str) -> Option<Vec<toml::Value>> {
self.get(key).and_then(|value| value.as_array())
.map(|value| value.to_vec())
}
} }