summaryrefslogtreecommitdiffstats
path: root/src/file/mod.rs
diff options
context:
space:
mode:
authorRyan Leckey <ryan@launchbadge.com>2017-06-22 14:14:29 -0700
committerRyan Leckey <ryan@launchbadge.com>2017-06-22 14:30:51 -0700
commit2b438ed9b53fee5689032f3b5fcdda8d15becd5f (patch)
tree48374e66a6594c7d11d19fe38f7e23df731b52be /src/file/mod.rs
parent04d3ee8f70337e4899932b92262fbeec2dbb1bd9 (diff)
Add builder API to Config
Diffstat (limited to 'src/file/mod.rs')
-rw-r--r--src/file/mod.rs32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/file/mod.rs b/src/file/mod.rs
index 7fc25c8..671f579 100644
--- a/src/file/mod.rs
+++ b/src/file/mod.rs
@@ -10,6 +10,7 @@ use std::path::Path;
use self::source::FileSource;
pub use self::format::FileFormat;
+#[derive(Clone, Debug)]
pub struct File<T>
where T: FileSource
{
@@ -70,12 +71,19 @@ impl<T: FileSource> File<T> {
}
}
-impl<T: FileSource> Source for File<T> {
+impl<T: FileSource> Source for File<T>
+ where T: 'static,
+ T: Sync + Send
+{
+ fn clone_into_box(&self) -> Box<Source + Send + Sync> {
+ Box::new((*self).clone())
+ }
+
fn collect(&self) -> Result<HashMap<String, Value>> {
// Coerce the file contents to a string
- let (uri, contents, format) = match self.source.resolve(self.format).map_err(|err| {
- ConfigError::Foreign(err)
- }) {
+ let (uri, contents, format) = match self.source
+ .resolve(self.format)
+ .map_err(|err| ConfigError::Foreign(err)) {
Ok((uri, contents, format)) => (uri, contents, format),
Err(error) => {
@@ -88,13 +96,13 @@ impl<T: FileSource> Source for File<T> {
};
// Parse the string using the given format
- let result = format.parse(uri.as_ref(), &contents, self.namespace.as_ref()).map_err(|cause| {
- ConfigError::FileParse {
- uri: uri,
- cause: cause
- }
- });
-
- result
+ format
+ .parse(uri.as_ref(), &contents, self.namespace.as_ref())
+ .map_err(|cause| {
+ ConfigError::FileParse {
+ uri: uri,
+ cause: cause,
+ }
+ })
}
}