From 14224be23dc2f253a240b85214927d97e1160669 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sun, 30 Jul 2017 13:20:36 -0700 Subject: Remove ConfigResult; close #36 --- examples/hierarchical-env/src/settings.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'examples/hierarchical-env') 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 { 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::("database.url")); // You can deserialize (and thus freeze) the entire configuration as - s.deserialize().unwrap() + s.deserialize() } } -- cgit v1.2.3