summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Leckey <leckey.ryan@gmail.com>2017-02-12 11:04:30 -0800
committerRyan Leckey <leckey.ryan@gmail.com>2017-02-12 11:04:30 -0800
commite29748b255ce97dfe9b4efcfbc4d9bcb3d694b97 (patch)
tree1b544db4cee3b392463edda743c3513c73f73459
parente0fe3e151c24ab81f8d232b3e18841acacc3656e (diff)
Decorate Box<Source> with Send + Sync
-rw-r--r--src/config.rs6
-rw-r--r--src/env.rs2
-rw-r--r--src/file/json.rs2
-rw-r--r--src/file/mod.rs12
-rw-r--r--src/file/toml.rs2
-rw-r--r--src/file/yaml.rs2
-rw-r--r--src/source.rs2
7 files changed, 14 insertions, 14 deletions
diff --git a/src/config.rs b/src/config.rs
index 403f566..ad4cda2 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -29,7 +29,7 @@ enum ConfigStore {
overrides: HashMap<String, Value>,
// Ordered list of sources
- sources: Vec<Box<Source>>,
+ sources: Vec<Box<Source + Send + Sync>>,
},
// TODO: Will be used for frozen configuratino soon
@@ -213,7 +213,7 @@ fn path_set_str(root: &mut HashMap<String, Value>, key: &str, value: &Value) {
impl ConfigStore {
fn merge<T>(&mut self, source: T) -> Result<(), Box<Error>>
- where T: SourceBuilder
+ where T: SourceBuilder + Send + Sync
{
if let ConfigStore::Mutable { ref mut sources, .. } = *self {
sources.push(source.build()?);
@@ -285,7 +285,7 @@ impl Config {
/// Merge in configuration values from the given source.
pub fn merge<T>(&mut self, source: T) -> Result<(), Box<Error>>
- where T: SourceBuilder
+ where T: SourceBuilder + Send + Sync
{
self.store.merge(source)?;
self.refresh()?;
diff --git a/src/env.rs b/src/env.rs
index dd237db..5c80bad 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -21,7 +21,7 @@ impl Environment {
}
impl source::SourceBuilder for Environment {
- fn build(&self) -> Result<Box<source::Source>, Box<Error>> {
+ fn build(&self) -> Result<Box<source::Source + Send + Sync>, Box<Error>> {
Ok(Box::new(self.clone()))
}
}
diff --git a/src/file/json.rs b/src/file/json.rs
index 64c6236..e6cc2f4 100644
--- a/src/file/json.rs
+++ b/src/file/json.rs
@@ -11,7 +11,7 @@ pub struct Content {
}
impl Content {
- pub fn parse(text: &str, namespace: Option<&String>) -> Result<Box<Source>, Box<Error>> {
+ pub fn parse(text: &str, namespace: Option<&String>) -> Result<Box<Source + Send + Sync>, Box<Error>> {
// Parse
let mut root: serde_json::Value = serde_json::from_str(text)?;
diff --git a/src/file/mod.rs b/src/file/mod.rs
index 6c72c37..7f7c0fb 100644
--- a/src/file/mod.rs
+++ b/src/file/mod.rs
@@ -47,7 +47,7 @@ impl FileFormat {
}
#[allow(unused_variables)]
- fn parse(&self, text: &str, namespace: Option<&String>) -> Result<Box<Source>, Box<Error>> {
+ fn parse(&self, text: &str, namespace: Option<&String>) -> Result<Box<Source + Send + Sync>, Box<Error>> {
match *self {
#[cfg(feature = "toml")]
FileFormat::Toml => toml::Content::parse(text, namespace),
@@ -65,7 +65,7 @@ pub trait FileSource {
fn try_build(&self,
format: FileFormat,
namespace: Option<&String>)
- -> Result<Box<Source>, Box<Error>>;
+ -> Result<Box<Source + Send + Sync>, Box<Error>>;
}
pub struct FileSourceString(String);
@@ -74,7 +74,7 @@ impl FileSource for FileSourceString {
fn try_build(&self,
format: FileFormat,
namespace: Option<&String>)
- -> Result<Box<Source>, Box<Error>> {
+ -> Result<Box<Source + Send + Sync>, Box<Error>> {
format.parse(&self.0, namespace)
}
}
@@ -132,7 +132,7 @@ impl FileSource for FileSourceFile {
fn try_build(&self,
format: FileFormat,
namespace: Option<&String>)
- -> Result<Box<Source>, Box<Error>> {
+ -> Result<Box<Source + Send + Sync>, Box<Error>> {
// Find file
let filename = self.find_file(format)?;
@@ -195,7 +195,7 @@ impl<T: FileSource> File<T> {
}
// Build normally and return error on failure
- fn try_build(&self) -> Result<Box<Source>, Box<Error>> {
+ fn try_build(&self) -> Result<Box<Source + Send + Sync>, Box<Error>> {
self.source.try_build(self.format, self.namespace.as_ref())
}
}
@@ -209,7 +209,7 @@ impl File<FileSourceFile> {
impl<T: FileSource> SourceBuilder for File<T> {
// Use try_build but only pass an error through if this source
// is required
- fn build(&self) -> Result<Box<Source>, Box<Error>> {
+ fn build(&self) -> Result<Box<Source + Send + Sync>, Box<Error>> {
if self.required {
self.try_build()
} else {
diff --git a/src/file/toml.rs b/src/file/toml.rs
index e3fb0d8..9b07cf0 100644
--- a/src/file/toml.rs
+++ b/src/file/toml.rs
@@ -10,7 +10,7 @@ pub struct Content {
}
impl Content {
- pub fn parse(text: &str, namespace: Option<&String>) -> Result<Box<Source>, Box<Error>> {
+ pub fn parse(text: &str, namespace: Option<&String>) -> Result<Box<Source + Send + Sync>, Box<Error>> {
// Parse
let mut parser = toml::Parser::new(text);
// TODO: Get a solution to make this return an Error-able
diff --git a/src/file/yaml.rs b/src/file/yaml.rs
index 7a70a4e..95a64b4 100644
--- a/src/file/yaml.rs
+++ b/src/file/yaml.rs
@@ -13,7 +13,7 @@ pub struct Content {
}
impl Content {
- pub fn parse(text: &str, namespace: Option<&String>) -> Result<Box<Source>, Box<Error>> {
+ pub fn parse(text: &str, namespace: Option<&String>) -> Result<Box<Source + Send + Sync>, Box<Error>> {
let mut docs = yaml::YamlLoader::load_from_str(text)?;
// Designate root
diff --git a/src/source.rs b/src/source.rs
index e136176..2048791 100644
--- a/src/source.rs
+++ b/src/source.rs
@@ -8,5 +8,5 @@ pub trait Source {
}
pub trait SourceBuilder {
- fn build(&self) -> Result<Box<Source>, Box<Error>>;
+ fn build(&self) -> Result<Box<Source + Send + Sync>, Box<Error>>;
}