From a0fc361a4b3413ea99631786b4b256bb377788d5 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sun, 30 Jul 2017 13:58:32 -0700 Subject: Rename examples/pattern -> examples/glob --- examples/glob/src/main.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 examples/glob/src/main.rs (limited to 'examples/glob/src/main.rs') 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::>().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::>().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::>()) + .unwrap(); + + // Print out our settings (as a HashMap) + println!("\n{:?} \n\n-----------", + settings.deserialize::>().unwrap()); +} -- cgit v1.2.3