summaryrefslogtreecommitdiffstats
path: root/examples/global
diff options
context:
space:
mode:
authorRyan Leckey <leckey.ryan@gmail.com>2017-07-30 13:20:36 -0700
committerRyan Leckey <leckey.ryan@gmail.com>2017-07-30 13:20:36 -0700
commit14224be23dc2f253a240b85214927d97e1160669 (patch)
tree6f5b02b26aef5cf37bb14f32b9048165b67109ce /examples/global
parent71f4b182d1e56febda64bd620ae0e0f65de333cd (diff)
Remove ConfigResult; close #36
Diffstat (limited to 'examples/global')
-rw-r--r--examples/global/Cargo.toml7
-rw-r--r--examples/global/src/main.rs26
2 files changed, 33 insertions, 0 deletions
diff --git a/examples/global/Cargo.toml b/examples/global/Cargo.toml
new file mode 100644
index 0000000..ec24740
--- /dev/null
+++ b/examples/global/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "global"
+version = "0.1.0"
+
+[dependencies]
+config = { path = "../../" }
+lazy_static = "^0.2.8"
diff --git a/examples/global/src/main.rs b/examples/global/src/main.rs
new file mode 100644
index 0000000..4fe0864
--- /dev/null
+++ b/examples/global/src/main.rs
@@ -0,0 +1,26 @@
+#[macro_use]
+extern crate lazy_static;
+
+extern crate config;
+
+use std::error::Error;
+use std::sync::RwLock;
+use config::Config;
+
+lazy_static! {
+ static ref SETTINGS: RwLock<Config> = RwLock::new(Config::default());
+}
+
+fn try_main() -> Result<(), Box<Error>> {
+ // Set property
+ SETTINGS.write()?.set("property", 42)?;
+
+ // Get property
+ println!("property: {}", SETTINGS.read()?.get::<i32>("property")?);
+
+ Ok(())
+}
+
+fn main() {
+ try_main().unwrap()
+}