diff options
author | Ryan Leckey <leckey.ryan@gmail.com> | 2017-03-08 11:09:37 -0800 |
---|---|---|
committer | Ryan Leckey <leckey.ryan@gmail.com> | 2017-03-08 11:09:37 -0800 |
commit | 2dc6a74b84825f65142c1fa7d3e67cd4f35ee3cb (patch) | |
tree | 23b21f732efbb215498db6debf6dbaee3af7e94f /examples/file-toml/src/main.rs | |
parent | c9ee1568fe212e4c352ec1afc52db44b34348fcd (diff) |
Initial work on deep serde integration
Diffstat (limited to 'examples/file-toml/src/main.rs')
-rw-r--r-- | examples/file-toml/src/main.rs | 18 |
1 files changed, 14 insertions, 4 deletions
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()); } |