add method to get vec from config
This commit is contained in:
parent
4bfe6e2aec
commit
9052a3b26b
@ -1,11 +1,18 @@
|
||||
use toml;
|
||||
use toml::value::Table;
|
||||
|
||||
pub trait Config {
|
||||
fn get_string (&self, key: &str) -> Option<&str>;
|
||||
fn get_vec (&self, key: &str) -> Option<Vec<toml::Value>>;
|
||||
}
|
||||
|
||||
impl Config for Table {
|
||||
fn get_string (&self, key: &str) -> Option<&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())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user