mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Reorganize parsing
This commit is contained in:
parent
ffc6778822
commit
30f427b61c
@ -59,16 +59,27 @@ pub struct Config {
|
|||||||
static mut CONF: Option<Config> = None;
|
static mut CONF: Option<Config> = None;
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
fn yaml_u64(parsed: &Yaml, name: &str) -> u64 {
|
fn yaml_str(parsed: &Yaml, name: &str) -> String {
|
||||||
parsed[name].as_i64().expect(format!("{} is missing (int)", name).as_str()) as u64
|
match &parsed[name] {
|
||||||
|
Yaml::Real(r) | Yaml::String(r) => r.to_string(),
|
||||||
|
Yaml::Integer(i) => i.to_string(),
|
||||||
|
Yaml::Boolean(true) => "true".to_string(),
|
||||||
|
Yaml::Boolean(false) => "false".to_string(),
|
||||||
|
Yaml::Array(_) | Yaml::Hash(_) | Yaml::Alias(_) | Yaml::Null => {
|
||||||
|
panic!("{} can not be converted to string", name);
|
||||||
|
}
|
||||||
|
Yaml::BadValue => {
|
||||||
|
panic!("{} is missing", name);
|
||||||
|
}
|
||||||
|
}.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn yaml_str(parsed: &Yaml, name: &str) -> String {
|
fn yaml_u64(parsed: &Yaml, name: &str) -> u64 {
|
||||||
parsed[name].as_str().expect(format!("{} is missing (str)", name).as_str()).to_string()
|
Self::yaml_str(parsed, name).parse().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn yaml_bool(parsed: &Yaml, name: &str) -> bool {
|
fn yaml_bool(parsed: &Yaml, name: &str) -> bool {
|
||||||
parsed[name].as_bool().expect(format!("{} is missing (bool)", name).as_str())
|
Self::yaml_str(parsed, name).to_lowercase().eq("true")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load the configuration from a given path
|
/// Load the configuration from a given path
|
||||||
|
Loading…
Reference in New Issue
Block a user