diff options
author | Ryan Leckey <leckey.ryan@gmail.com> | 2017-07-30 13:20:36 -0700 |
---|---|---|
committer | Ryan Leckey <leckey.ryan@gmail.com> | 2017-07-30 13:20:36 -0700 |
commit | 14224be23dc2f253a240b85214927d97e1160669 (patch) | |
tree | 6f5b02b26aef5cf37bb14f32b9048165b67109ce /examples/hierarchical-env/src/settings.rs | |
parent | 71f4b182d1e56febda64bd620ae0e0f65de333cd (diff) |
Remove ConfigResult; close #36
Diffstat (limited to 'examples/hierarchical-env/src/settings.rs')
-rw-r--r-- | examples/hierarchical-env/src/settings.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/examples/hierarchical-env/src/settings.rs b/examples/hierarchical-env/src/settings.rs index 43897b3..9e07054 100644 --- a/examples/hierarchical-env/src/settings.rs +++ b/examples/hierarchical-env/src/settings.rs @@ -1,5 +1,5 @@ use std::env; -use config::{Config, File, Environment}; +use config::{ConfigError, Config, File, Environment}; #[derive(Debug, Deserialize)] struct Database { @@ -37,34 +37,34 @@ pub struct Settings { } impl Settings { - pub fn new() -> Self { + pub fn new() -> Result<Self, ConfigError> { let mut s = Config::new(); // Start off by merging in the "default" configuration file - s.merge(File::with_name("config/default")).unwrap(); + s.merge(File::with_name("config/default"))?; // Add in the current environment file // Default to 'development' env // Note that this file is _optional_ let env = env::var("RUN_MODE").unwrap_or("development".into()); - s.merge(File::with_name(&format!("config/{}", env)).required(false)).unwrap(); + s.merge(File::with_name(&format!("config/{}", env)).required(false))?; // Add in a local configuration file // This file shouldn't be checked in to git - s.merge(File::with_name("config/local").required(false)).unwrap(); + s.merge(File::with_name("config/local").required(false))?; // Add in settings from the environment (with a prefix of APP) // Eg.. `APP_DEBUG=1 ./target/app` would set the `debug` key - s.merge(Environment::with_prefix("app")).unwrap(); + s.merge(Environment::with_prefix("app"))?; // You may also programmatically change settings - s.set("database.url", "postgres://").unwrap(); + s.set("database.url", "postgres://")?; // Now that we're done, let's access our configuration println!("debug: {:?}", s.get_bool("debug")); println!("database: {:?}", s.get::<String>("database.url")); // You can deserialize (and thus freeze) the entire configuration as - s.deserialize().unwrap() + s.deserialize() } } |