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;