blob: 0fa3d7031554125c7df3353fa4c5d03a14ba8472 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#![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 env;
mod config;
use std::error::Error;
use std::sync::{Once, ONCE_INIT};
pub use source::{Source, SourceBuilder};
pub use file::{File, FileFormat};
pub use env::Environment;
pub use value::Value;
pub use config::Config;
// Global configuration
static mut CONFIG: Option<Config> = None;
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.as_mut().unwrap()
}
}
pub fn merge<T>(source: T) -> Result<(), Box<Error>>
where T: SourceBuilder
{
global().merge(source)
}
pub fn set_default<T>(key: &str, value: T)
where T: Into<Value>
{
global().set_default(key, value)
}
pub fn set<T>(key: &str, value: T)
where T: Into<Value>
{
global().set(key, value)
}
pub fn get(key: &str) -> Option<Value> {
global().get(key)
}
pub fn get_str(key: &str) -> Option<String> {
global().get_str(key)
}
pub fn get_int(key: &str) -> Option<i64> {
global().get_int(key)
}
pub fn get_float(key: &str) -> Option<f64> {
global().get_float(key)
}
pub fn get_bool(key: &str) -> Option<bool> {
global().get_bool(key)
}
|