summaryrefslogtreecommitdiffstats
path: root/src/env.rs
diff options
context:
space:
mode:
authorRyan Leckey <leckey.ryan@gmail.com>2017-03-08 11:09:37 -0800
committerRyan Leckey <leckey.ryan@gmail.com>2017-03-08 11:09:37 -0800
commit2dc6a74b84825f65142c1fa7d3e67cd4f35ee3cb (patch)
tree23b21f732efbb215498db6debf6dbaee3af7e94f /src/env.rs
parentc9ee1568fe212e4c352ec1afc52db44b34348fcd (diff)
Initial work on deep serde integration
Diffstat (limited to 'src/env.rs')
-rw-r--r--src/env.rs60
1 files changed, 0 insertions, 60 deletions
diff --git a/src/env.rs b/src/env.rs
deleted file mode 100644
index 5c80bad..0000000
--- a/src/env.rs
+++ /dev/null
@@ -1,60 +0,0 @@
-use std::env;
-use std::error::Error;
-use std::collections::HashMap;
-
-use source;
-use value::Value;
-
-#[derive(Clone)]
-pub struct Environment {
- /// Optional prefix that would restrict environment consideration
- /// to only variables which begin with that prefix.
- prefix: Option<String>,
-}
-
-impl Environment {
- pub fn new<'a, T>(prefix: T) -> Environment
- where T: Into<Option<&'a str>>
- {
- Environment { prefix: prefix.into().map(String::from) }
- }
-}
-
-impl source::SourceBuilder for Environment {
- fn build(&self) -> Result<Box<source::Source + Send + Sync>, Box<Error>> {
- Ok(Box::new(self.clone()))
- }
-}
-
-impl source::Source for Environment {
- fn collect(&self) -> HashMap<String, Value> {
- // Iterate through environment variables
- let mut r = HashMap::new();
-
- // Make prefix pattern
- let prefix_pat = if let Some(ref prefix) = self.prefix {
- Some(prefix.clone() + "_".into())
- } else {
- None
- };
-
- for (key, value) in env::vars() {
- let mut key = key.to_string();
-
- // Check if key matches prefix
- if let Some(ref prefix_pat) = prefix_pat {
- if key.starts_with(prefix_pat) {
- // Remove the prefix from the key
- key = key[prefix_pat.len()..].to_string();
- } else {
- // Skip this key
- continue;
- }
- }
-
- r.insert(key, Value::String(value));
- }
-
- r
- }
-}