summaryrefslogtreecommitdiffstats
path: root/examples/glob/src/main.rs
diff options
context:
space:
mode:
authorRyan Leckey <leckey.ryan@gmail.com>2017-07-30 13:58:32 -0700
committerRyan Leckey <leckey.ryan@gmail.com>2017-07-30 13:58:32 -0700
commita0fc361a4b3413ea99631786b4b256bb377788d5 (patch)
treebb4fb3d1d2f8230f4e344db46c1e6c8750ce7a31 /examples/glob/src/main.rs
parent011b809e104242f7fe9f6c00a54804b1cf0e125c (diff)
Rename examples/pattern -> examples/glob
Diffstat (limited to 'examples/glob/src/main.rs')
-rw-r--r--examples/glob/src/main.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/glob/src/main.rs b/examples/glob/src/main.rs
new file mode 100644
index 0000000..f88f1ed
--- /dev/null
+++ b/examples/glob/src/main.rs
@@ -0,0 +1,52 @@
+extern crate glob;
+extern crate config;
+
+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.deserialize::<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.deserialize::<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.deserialize::<HashMap<String, String>>().unwrap());
+}