Add config module
This commit is contained in:
parent
0363a6a4d4
commit
ef86c5e1ff
2 changed files with 20 additions and 0 deletions
19
libimagdiary/src/config.rs
Normal file
19
libimagdiary/src/config.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use toml::Value;
|
||||
|
||||
use libimagrt::runtime::Runtime;
|
||||
|
||||
pub fn get_default_diary_name(rt: &Runtime) -> Option<String> {
|
||||
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"))
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue