diff options
author | Ryan Leckey <leckey.ryan@gmail.com> | 2017-01-26 19:02:13 -0800 |
---|---|---|
committer | Ryan Leckey <leckey.ryan@gmail.com> | 2017-01-26 19:02:13 -0800 |
commit | 589036c19409c7626a5bafda5af96c2fbc6a7de5 (patch) | |
tree | 9f4e09809df7c200c3d60b619c7eea9b91e6d70c /examples | |
parent | d7ad51c8851fe3c845569760935fae1828e859b5 (diff) |
Refactor the file source to allow for N formats; implement JSON.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/basic/Cargo.toml | 3 | ||||
-rw-r--r-- | examples/file-json/Cargo.toml | 6 | ||||
-rw-r--r-- | examples/file-json/Settings.json | 5 | ||||
-rw-r--r-- | examples/file-json/src/main.rs | 10 | ||||
-rw-r--r-- | examples/file-toml/Cargo.toml (renamed from examples/basic-file/Cargo.toml) | 3 | ||||
-rw-r--r-- | examples/file-toml/src/main.rs (renamed from examples/basic-file/src/main.rs) | 2 |
6 files changed, 24 insertions, 5 deletions
diff --git a/examples/basic/Cargo.toml b/examples/basic/Cargo.toml index 2cb273b..7ede162 100644 --- a/examples/basic/Cargo.toml +++ b/examples/basic/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "basic" version = "0.1.0" -authors = ["Ryan Leckey <leckey.ryan@gmail.com>"] [dependencies] -config = { path = "../.." } +config = { path = "../..", default-features = false } diff --git a/examples/file-json/Cargo.toml b/examples/file-json/Cargo.toml new file mode 100644 index 0000000..7223f35 --- /dev/null +++ b/examples/file-json/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "file-json" +version = "0.1.0" + +[dependencies] +config = { path = "../..", default-features = false, features = ["json"] } diff --git a/examples/file-json/Settings.json b/examples/file-json/Settings.json new file mode 100644 index 0000000..72b28e6 --- /dev/null +++ b/examples/file-json/Settings.json @@ -0,0 +1,5 @@ +{ + "debug": false, + "pi": 3.14159, + "weight": 150 +} diff --git a/examples/file-json/src/main.rs b/examples/file-json/src/main.rs new file mode 100644 index 0000000..9c636ac --- /dev/null +++ b/examples/file-json/src/main.rs @@ -0,0 +1,10 @@ +extern crate config; + +fn main() { + // Read configuration from "Settings.json" + config::merge(config::File::new("Settings", config::FileFormat::Json)).unwrap(); + + println!("debug = {:?}", config::get("debug")); + println!("pi = {:?}", config::get("pi")); + println!("weight = {:?}", config::get("weight")); +} diff --git a/examples/basic-file/Cargo.toml b/examples/file-toml/Cargo.toml index ffef864..6f45799 100644 --- a/examples/basic-file/Cargo.toml +++ b/examples/file-toml/Cargo.toml @@ -1,7 +1,6 @@ [package] -name = "basic-file" +name = "file-toml" version = "0.1.0" -authors = ["Ryan Leckey <leckey.ryan@gmail.com>"] [dependencies] config = { path = "../.." } diff --git a/examples/basic-file/src/main.rs b/examples/file-toml/src/main.rs index ae394f9..03ce61a 100644 --- a/examples/basic-file/src/main.rs +++ b/examples/file-toml/src/main.rs @@ -2,7 +2,7 @@ extern crate config; fn main() { // Read configuration from $(cwd)/Cargo.toml - config::merge(config::File::with_name("Cargo")).unwrap(); + config::merge(config::File::new("Cargo", config::FileFormat::Toml)).unwrap(); println!("package.name = {:?}", config::get_str("package.name")); println!("package.version = {:?}", config::get_str("package.version")); |