summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Fochler <mail@christianfochler.de>2018-01-29 08:05:59 +0100
committerChristian Fochler <mail@christianfochler.de>2018-01-29 08:05:59 +0100
commit5ba6b7a437912ff40a216d3f99f963998b408911 (patch)
tree1b54afaf9c5cce2d9bb7b3a7f2867ae95ca4d568
parent52ed0762dff1514e0cb970528c6432caea479444 (diff)
add default prefix separator
- no need to add '_' to the prefix
-rw-r--r--examples/hierarchical-env/src/settings.rs2
-rw-r--r--examples/simple/src/main.rs2
-rw-r--r--src/env.rs6
-rw-r--r--tests/env.rs2
4 files changed, 6 insertions, 6 deletions
diff --git a/examples/hierarchical-env/src/settings.rs b/examples/hierarchical-env/src/settings.rs
index 75a9186..bde5819 100644
--- a/examples/hierarchical-env/src/settings.rs
+++ b/examples/hierarchical-env/src/settings.rs
@@ -55,7 +55,7 @@ impl Settings {
// 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_"))?;
+ s.merge(Environment::with_prefix("app"))?;
// You may also programmatically change settings
s.set("database.url", "postgres://")?;
diff --git a/examples/simple/src/main.rs b/examples/simple/src/main.rs
index 67a1069..8c738a8 100644
--- a/examples/simple/src/main.rs
+++ b/examples/simple/src/main.rs
@@ -9,7 +9,7 @@ fn main() {
.merge(config::File::with_name("Settings")).unwrap()
// Add in settings from the environment (with a prefix of APP_)
// Eg.. `APP_DEBUG=1 ./target/app` would set the `debug` key
- .merge(config::Environment::with_prefix("APP_")).unwrap();
+ .merge(config::Environment::with_prefix("APP")).unwrap();
// Print out our settings (as a HashMap)
println!("{:?}",
diff --git a/src/env.rs b/src/env.rs
index 5f7e92f..b26dc56 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -9,10 +9,10 @@ pub struct Environment {
/// Optional prefix that will limit access to the environment to only keys that
/// begin with the defined prefix.
///
- /// A prefix is tested to be present on each key before its considered
+ /// A prefix with a separator of `_` is tested to be present on each key before its considered
/// to be part of the source environment.
///
- /// For example, the key `CONFIG_DEBUG` would become `DEBUG` with a prefix of `config_`.
+ /// For example, the key `CONFIG_DEBUG` would become `DEBUG` with a prefix of `config`.
prefix: Option<String>,
/// Optional character sequence that separates each key segment in an environment key pattern.
@@ -69,7 +69,7 @@ impl Source for Environment {
// Define a prefix pattern to test and exclude from keys
let prefix_pattern = match self.prefix {
- Some(ref prefix) => Some(prefix.clone() + &separator),
+ Some(ref prefix) => Some(prefix.clone() + "_"),
_ => None,
};
diff --git a/tests/env.rs b/tests/env.rs
index fc93f15..2a55d7f 100644
--- a/tests/env.rs
+++ b/tests/env.rs
@@ -18,7 +18,7 @@ fn test_default() {
fn test_prefix_is_removed_from_key() {
env::set_var("B_A_C", "abc");
- let environment = Environment::with_prefix("B_");
+ let environment = Environment::with_prefix("B");
assert!(environment.collect().unwrap().contains_key("a_c"));