blob: b3183ef762e0eae77d939e11b1cce1f9714fea23 (
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
|
use std::path::Path;
use std::collections::HashMap;
use config::*;
use glob::glob;
fn main() {
// Option 1
// --------
// Gather all conf files from conf/ manually
let mut settings = Config::default();
settings
// File::with_name(..) is shorthand for File::from(Path::new(..))
.merge(File::with_name("conf/00-default.toml")).unwrap()
.merge(File::from(Path::new("conf/05-some.yml"))).unwrap()
.merge(File::from(Path::new("conf/99-extra.json"))).unwrap();
// Print out our settings (as a HashMap)
println!("\n{:?} \n\n-----------",
settings.try_into::<HashMap<String, String>>().unwrap());
// Option 2
// --------
// Gather all conf files from conf/ manually, but put in 1 merge call.
let mut settings = Config::default();
settings
.merge(vec![File::with_name("conf/00-default.toml"),
File::from(Path::new("conf/05-some.yml")),
File::from(Path::new("conf/99-extra.json"))])
.unwrap();
// Print out our settings (as a HashMap)
println!("\n{:?} \n\n-----------",
settings.try_into::<HashMap<String, String>>().unwrap());
// Option 3
// --------
// Gather all conf files from conf/ using glob and put in 1 merge call.
let mut settings = Config::default();
settings
.merge(glob("conf/*")
.unwrap()
.map(|path| File::from(path.unwrap()))
.collect::<Vec<_>>())
.unwrap();
// Print out our settings (as a HashMap)
println!("\n{:?} \n\n-----------",
settings.try_into::<HashMap<String, String>>().unwrap());
}
|