summaryrefslogtreecommitdiffstats
path: root/src/file/source
diff options
context:
space:
mode:
authorRyan Leckey <leckey.ryan@gmail.com>2017-07-30 13:20:36 -0700
committerRyan Leckey <leckey.ryan@gmail.com>2017-07-30 13:20:36 -0700
commit14224be23dc2f253a240b85214927d97e1160669 (patch)
tree6f5b02b26aef5cf37bb14f32b9048165b67109ce /src/file/source
parent71f4b182d1e56febda64bd620ae0e0f65de333cd (diff)
Remove ConfigResult; close #36
Diffstat (limited to 'src/file/source')
-rw-r--r--src/file/source/file.rs71
-rw-r--r--src/file/source/mod.rs7
-rw-r--r--src/file/source/string.rs15
3 files changed, 53 insertions, 40 deletions
diff --git a/src/file/source/file.rs b/src/file/source/file.rs
index 7bf29be..80cd1dd 100644
--- a/src/file/source/file.rs
+++ b/src/file/source/file.rs
@@ -2,7 +2,7 @@ use std::str::FromStr;
use std::result;
use std::error::Error;
-use std::path::{PathBuf, Path};
+use std::path::{Path, PathBuf};
use file::format::ALL_EXTENSIONS;
use std::io::{self, Read};
use std::fs;
@@ -24,9 +24,10 @@ impl FileSourceFile {
FileSourceFile { name: name }
}
- fn find_file(&self,
- format_hint: Option<FileFormat>)
- -> Result<(PathBuf, FileFormat), Box<Error + Send + Sync>> {
+ fn find_file(
+ &self,
+ format_hint: Option<FileFormat>,
+ ) -> Result<(PathBuf, FileFormat), Box<Error + Send + Sync>> {
// First check for an _exact_ match
let mut filename = env::current_dir()?.as_path().join(self.name.clone());
if filename.is_file() {
@@ -35,55 +36,61 @@ impl FileSourceFile {
None => {
for (format, extensions) in ALL_EXTENSIONS.iter() {
if extensions.contains(&filename
- .extension()
- .unwrap_or_default()
- .to_string_lossy()
- .as_ref()) {
+ .extension()
+ .unwrap_or_default()
+ .to_string_lossy()
+ .as_ref())
+ {
return Ok((filename, *format));
}
}
- Err(Box::new(io::Error::new(io::ErrorKind::NotFound,
- format!("configuration file \"{}\" is not of a registered file format",
- filename.to_string_lossy()))))
+ Err(Box::new(io::Error::new(
+ io::ErrorKind::NotFound,
+ format!(
+ "configuration file \"{}\" is not of a registered file format",
+ filename.to_string_lossy()
+ ),
+ )))
}
};
}
match format_hint {
- Some(format) => {
- for ext in format.extensions() {
- filename.set_extension(ext);
+ Some(format) => for ext in format.extensions() {
+ filename.set_extension(ext);
- if filename.is_file() {
- return Ok((filename, format));
- }
+ if filename.is_file() {
+ return Ok((filename, format));
}
- }
+ },
- None => {
- for (format, extensions) in ALL_EXTENSIONS.iter() {
- for ext in format.extensions() {
- filename.set_extension(ext);
+ None => for (format, extensions) in ALL_EXTENSIONS.iter() {
+ for ext in format.extensions() {
+ filename.set_extension(ext);
- if filename.is_file() {
- return Ok((filename, *format));
- }
+ if filename.is_file() {
+ return Ok((filename, *format));
}
}
- }
+ },
}
- Err(Box::new(io::Error::new(io::ErrorKind::NotFound,
- format!("configuration file \"{}\" not found",
- self.name.to_string_lossy()))))
+ Err(Box::new(io::Error::new(
+ io::ErrorKind::NotFound,
+ format!(
+ "configuration file \"{}\" not found",
+ self.name.to_string_lossy()
+ ),
+ )))
}
}
impl FileSource for FileSourceFile {
- fn resolve(&self,
- format_hint: Option<FileFormat>)
- -> Result<(Option<String>, String, FileFormat), Box<Error + Send + Sync>> {
+ fn resolve(
+ &self,
+ format_hint: Option<FileFormat>,
+ ) -> Result<(Option<String>, String, FileFormat), Box<Error + Send + Sync>> {
// Find file
let (filename, format) = self.find_file(format_hint)?;
diff --git a/src/file/source/mod.rs b/src/file/source/mod.rs
index f164d27..4d9950f 100644
--- a/src/file/source/mod.rs
+++ b/src/file/source/mod.rs
@@ -9,7 +9,8 @@ use super::FileFormat;
/// Describes where the file is sourced
pub trait FileSource: Debug + Clone {
- fn resolve(&self,
- format_hint: Option<FileFormat>)
- -> Result<(Option<String>, String, FileFormat), Box<Error + Send + Sync>>;
+ fn resolve(
+ &self,
+ format_hint: Option<FileFormat>,
+ ) -> Result<(Option<String>, String, FileFormat), Box<Error + Send + Sync>>;
}
diff --git a/src/file/source/string.rs b/src/file/source/string.rs
index 5dbd1b9..9c89231 100644
--- a/src/file/source/string.rs
+++ b/src/file/source/string.rs
@@ -3,7 +3,7 @@ use std::result;
use std::error::Error;
use source::Source;
-use super::{FileSource, FileFormat};
+use super::{FileFormat, FileSource};
/// Describes a file sourced from a string
#[derive(Clone, Debug)]
@@ -16,9 +16,14 @@ impl<'a> From<&'a str> for FileSourceString {
}
impl FileSource for FileSourceString {
- fn resolve(&self,
- format_hint: Option<FileFormat>)
- -> Result<(Option<String>, String, FileFormat), Box<Error + Send + Sync>> {
- Ok((None, self.0.clone(), format_hint.expect("from_str requires a set file format")))
+ fn resolve(
+ &self,
+ format_hint: Option<FileFormat>,
+ ) -> Result<(Option<String>, String, FileFormat), Box<Error + Send + Sync>> {
+ Ok((
+ None,
+ self.0.clone(),
+ format_hint.expect("from_str requires a set file format"),
+ ))
}
}