diff options
author | Ryan Leckey <leckey.ryan@gmail.com> | 2017-02-12 10:02:07 -0800 |
---|---|---|
committer | Ryan Leckey <leckey.ryan@gmail.com> | 2017-02-12 10:02:07 -0800 |
commit | ccae9b09fa9d4650de3cf91013162a7277e46060 (patch) | |
tree | f2ff7c58a32f5418b48dd8327e6c45b74d20356c /examples/basic/src/main.rs | |
parent | bcd0737e15726f3ad324c3cf26c5d04fe5f75766 (diff) |
Remove global API
Diffstat (limited to 'examples/basic/src/main.rs')
-rw-r--r-- | examples/basic/src/main.rs | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/examples/basic/src/main.rs b/examples/basic/src/main.rs index 6690f0e..2f947d8 100644 --- a/examples/basic/src/main.rs +++ b/examples/basic/src/main.rs @@ -1,31 +1,33 @@ extern crate config; fn main() { + let mut c = config::Config::new(); + // Set defaults for `window.width` and `window.height` - config::set_default("window.title", "Basic").unwrap(); - config::set_default("window.width", 640).unwrap(); - config::set_default("window.height", 480).unwrap(); - config::set_default("debug", true).unwrap(); + c.set_default("window.title", "Basic").unwrap(); + c.set_default("window.width", 640).unwrap(); + c.set_default("window.height", 480).unwrap(); + c.set_default("debug", true).unwrap(); // Note that you can retrieve the stored values as any type as long // as there exists a reasonable conversion - println!("window.title : {:?}", config::get_str("window.title")); - println!("window.width : {:?}", config::get_str("window.width")); - println!("window.width : {:?}", config::get_int("window.width")); - println!("debug : {:?}", config::get_bool("debug")); - println!("debug : {:?}", config::get_str("debug")); - println!("debug : {:?}", config::get_int("debug")); + println!("window.title : {:?}", c.get_str("window.title")); + println!("window.width : {:?}", c.get_str("window.width")); + println!("window.width : {:?}", c.get_int("window.width")); + println!("debug : {:?}", c.get_bool("debug")); + println!("debug : {:?}", c.get_str("debug")); + println!("debug : {:?}", c.get_int("debug")); // Attempting to get a value as a type that cannot be reasonably // converted to will return None - println!("window.title : {:?}", config::get_bool("window.title")); + println!("window.title : {:?}", c.get_bool("window.title")); // Instead of using a get_* function you can get the variant // directly - println!("debug : {:?}", config::get("debug")); + println!("debug : {:?}", c.get("debug")); println!("debug : {:?}", - config::get("debug").unwrap().as_int()); + c.get("debug").unwrap().into_int()); // Attempting to get a value that does not exist will return None - println!("not-found : {:?}", config::get("not-found")); + println!("not-found : {:?}", c.get("not-found")); } |