summaryrefslogtreecommitdiffstats
path: root/src/env.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2019-10-29 20:01:30 -0700
committerDan Davison <dandavison7@gmail.com>2019-10-29 20:03:19 -0700
commitfa14a6b144df8a4fae995aa3608c414aad73ed9c (patch)
tree98081e0f8e0a2b1673ddc2174c3de251f036dbc7 /src/env.rs
parentf8d2151891a4c16b64f592949f3b5ce0cd0e0d4d (diff)
Add env module
Diffstat (limited to 'src/env.rs')
-rw-r--r--src/env.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/env.rs b/src/env.rs
new file mode 100644
index 00000000..60158b85
--- /dev/null
+++ b/src/env.rs
@@ -0,0 +1,10 @@
+use std::env;
+
+/// If key is set and, after trimming whitespace, is not empty string, then return that trimmed
+/// string. Else None.
+pub fn get_env_var(key: &str) -> Option<String> {
+ match env::var(key).unwrap_or("".to_string()).trim() {
+ "" => None,
+ non_empty_string => Some(non_empty_string.to_string()),
+ }
+}