From ef86c5e1ffbd8fb01c4c638d0da18256c2920391 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 22 Apr 2016 17:27:44 +0200 Subject: [PATCH] Add config module --- libimagdiary/src/config.rs | 19 +++++++++++++++++++ libimagdiary/src/lib.rs | 1 + 2 files changed, 20 insertions(+) create mode 100644 libimagdiary/src/config.rs diff --git a/libimagdiary/src/config.rs b/libimagdiary/src/config.rs new file mode 100644 index 00000000..93749289 --- /dev/null +++ b/libimagdiary/src/config.rs @@ -0,0 +1,19 @@ +use toml::Value; + +use libimagrt::runtime::Runtime; + +pub fn get_default_diary_name(rt: &Runtime) -> Option { + get_diary_config_section(rt) + .and_then(|config| { + match config.lookup("default_diary") { + Some(&Value::String(ref s)) => Some(s.clone()), + _ => None, + } + }) +} + +pub fn get_diary_config_section<'a>(rt: &'a Runtime) -> Option<&'a Value> { + rt.config() + .map(|config| config.config()) + .and_then(|config| config.lookup("diary")) +} diff --git a/libimagdiary/src/lib.rs b/libimagdiary/src/lib.rs index 5f4567e7..0e6256e6 100644 --- a/libimagdiary/src/lib.rs +++ b/libimagdiary/src/lib.rs @@ -13,6 +13,7 @@ extern crate libimagrt; module_entry_path_mod!("diary", "0.1.0"); +pub mod config; pub mod error; pub mod diaryid; pub mod diary;