19 lines
494 B
Rust
19 lines
494 B
Rust
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())
|
|
}
|
|
}
|