summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorRyan Leckey <ryan@launchbadge.com>2017-06-22 17:10:47 -0700
committerRyan Leckey <ryan@launchbadge.com>2017-06-22 17:10:47 -0700
commit6bfaf90fdf67197c511a7594b37d835e964edccd (patch)
treeaedca78e59887c30bd2e34626b06f24f29de0d81 /examples
parent159bb52c595384fed44a2c669198d50f2a758a9a (diff)
Implement Source for Vec<T: Source> and From<Path> for File
Diffstat (limited to 'examples')
-rw-r--r--examples/pattern/Cargo.toml6
-rw-r--r--examples/pattern/conf/00-default.toml1
-rw-r--r--examples/pattern/conf/05-some.yml2
-rw-r--r--examples/pattern/conf/99-extra.json5
-rw-r--r--examples/pattern/src/main.rs50
5 files changed, 64 insertions, 0 deletions
diff --git a/examples/pattern/Cargo.toml b/examples/pattern/Cargo.toml
new file mode 100644
index 0000000..98c5330
--- /dev/null
+++ b/examples/pattern/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "pattern"
+version = "0.1.0"
+
+[dependencies]
+config = { path = "../../", features = ["glob"] }
diff --git a/examples/pattern/conf/00-default.toml b/examples/pattern/conf/00-default.toml
new file mode 100644
index 0000000..7b95e7a
--- /dev/null
+++ b/examples/pattern/conf/00-default.toml
@@ -0,0 +1 @@
+debug = false
diff --git a/examples/pattern/conf/05-some.yml b/examples/pattern/conf/05-some.yml
new file mode 100644
index 0000000..52555a0
--- /dev/null
+++ b/examples/pattern/conf/05-some.yml
@@ -0,0 +1,2 @@
+secret: THIS IS SECRET
+debug: true
diff --git a/examples/pattern/conf/99-extra.json b/examples/pattern/conf/99-extra.json
new file mode 100644
index 0000000..26f908c
--- /dev/null
+++ b/examples/pattern/conf/99-extra.json
@@ -0,0 +1,5 @@
+{
+ "that": 3,
+ "this": 1230,
+ "key": "sdgnjklsdjklgds"
+}
diff --git a/examples/pattern/src/main.rs b/examples/pattern/src/main.rs
new file mode 100644
index 0000000..aaf164d
--- /dev/null
+++ b/examples/pattern/src/main.rs
@@ -0,0 +1,50 @@
+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 settings = Config::default()
+ // File::with_name(..) is shorthand for File::from(Path::new(..))
+ .merge(File::with_name("conf/00-default.toml"))
+ .merge(File::from(Path::new("conf/05-some.yml")))
+ .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 settings = Config::default()
+ .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 settings = Config::default()
+ .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());
+}