diff options
Diffstat (limited to 'examples/file-toml')
-rw-r--r-- | examples/file-toml/Cargo.toml | 5 | ||||
-rw-r--r-- | examples/file-toml/Settings.toml | 3 | ||||
-rw-r--r-- | examples/file-toml/src/main.rs | 18 |
3 files changed, 20 insertions, 6 deletions
diff --git a/examples/file-toml/Cargo.toml b/examples/file-toml/Cargo.toml index 6f45799..0501895 100644 --- a/examples/file-toml/Cargo.toml +++ b/examples/file-toml/Cargo.toml @@ -1,6 +1,9 @@ [package] name = "file-toml" version = "0.1.0" +workspace = "../../" [dependencies] -config = { path = "../.." } +config = { path = "../../lib", features = ["toml"] } +serde = "^0.9" +serde_derive = "^0.9" diff --git a/examples/file-toml/Settings.toml b/examples/file-toml/Settings.toml index 28c5fc6..21fa1e3 100644 --- a/examples/file-toml/Settings.toml +++ b/examples/file-toml/Settings.toml @@ -1,3 +1,4 @@ -debug = false +debug = true pi = 3.14159 weight = 150 +location = { x = 10, y = 30 } diff --git a/examples/file-toml/src/main.rs b/examples/file-toml/src/main.rs index 85db701..ddca412 100644 --- a/examples/file-toml/src/main.rs +++ b/examples/file-toml/src/main.rs @@ -1,12 +1,22 @@ extern crate config; +#[macro_use] +extern crate serde_derive; + +#[derive(Debug, Deserialize)] +struct Point { x: i64, y: i64 } + fn main() { - let mut c = config::Config::new(); + let mut c = config::Config::default(); // Read configuration from "Settings.toml" c.merge(config::File::new("Settings", config::FileFormat::Toml)).unwrap(); - println!("debug = {:?}", c.get("debug")); - println!("pi = {:?}", c.get("pi")); - println!("weight = {:?}", c.get("weight")); + // Simple key access to values + println!("debug = {}", c.get::<bool>("debug").unwrap()); + println!("pi = {}", c.get::<f64>("pi").unwrap()); + println!("weight = {}", c.get::<i64>("weight").unwrap()); + println!("location = {:?}", c.get::<Point>("location").unwrap()); + // println!("location.x = {}", c.get::<Point>("location.x").unwrap()); + // println!("location.y = {}", c.get::<Point>("location.y").unwrap()); } |