diff options
author | Ryan Leckey <leckey.ryan@gmail.com> | 2017-01-26 19:02:13 -0800 |
---|---|---|
committer | Ryan Leckey <leckey.ryan@gmail.com> | 2017-01-26 19:02:13 -0800 |
commit | 589036c19409c7626a5bafda5af96c2fbc6a7de5 (patch) | |
tree | 9f4e09809df7c200c3d60b619c7eea9b91e6d70c /src/lib.rs | |
parent | d7ad51c8851fe3c845569760935fae1828e859b5 (diff) |
Refactor the file source to allow for N formats; implement JSON.
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -1,19 +1,22 @@ #![feature(drop_types_in_const)] #![allow(unknown_lints)] +#[cfg(feature = "toml")] extern crate toml; +#[cfg(feature = "json")] +extern crate serde_json; + mod value; mod source; mod file; mod config; use std::error::Error; -use std::borrow::Cow; use std::sync::{Once, ONCE_INIT}; -pub use source::Source; -pub use file::File; +pub use source::{Source, SourceBuilder}; +pub use file::{File, FileFormat}; pub use value::Value; @@ -26,14 +29,16 @@ static CONFIG_INIT: Once = ONCE_INIT; // Get the global configuration instance fn global() -> &'static mut Config { unsafe { - CONFIG_INIT.call_once(|| { CONFIG = Some(Default::default()); }); + CONFIG_INIT.call_once(|| { + CONFIG = Some(Default::default()); + }); CONFIG.as_mut().unwrap() } } pub fn merge<T>(source: T) -> Result<(), Box<Error>> - where T: Source + where T: SourceBuilder { global().merge(source) } @@ -54,11 +59,11 @@ pub fn set<T>(key: &str, value: T) global().set(key, value) } -pub fn get<'a>(key: &str) -> Option<&'a Value> { +pub fn get(key: &str) -> Option<Value> { global().get(key) } -pub fn get_str<'a>(key: &str) -> Option<Cow<'a, str>> { +pub fn get_str(key: &str) -> Option<String> { global().get_str(key) } |