From 14224be23dc2f253a240b85214927d97e1160669 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sun, 30 Jul 2017 13:20:36 -0700 Subject: Remove ConfigResult; close #36 --- src/file/source/file.rs | 71 ++++++++++++++++++++++++++--------------------- src/file/source/mod.rs | 7 +++-- src/file/source/string.rs | 15 ++++++---- 3 files changed, 53 insertions(+), 40 deletions(-) (limited to 'src/file/source') 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) - -> Result<(PathBuf, FileFormat), Box> { + fn find_file( + &self, + format_hint: Option, + ) -> Result<(PathBuf, FileFormat), Box> { // 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) - -> Result<(Option, String, FileFormat), Box> { + fn resolve( + &self, + format_hint: Option, + ) -> Result<(Option, String, FileFormat), Box> { // 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) - -> Result<(Option, String, FileFormat), Box>; + fn resolve( + &self, + format_hint: Option, + ) -> Result<(Option, String, FileFormat), Box>; } 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) - -> Result<(Option, String, FileFormat), Box> { - Ok((None, self.0.clone(), format_hint.expect("from_str requires a set file format"))) + fn resolve( + &self, + format_hint: Option, + ) -> Result<(Option, String, FileFormat), Box> { + Ok(( + None, + self.0.clone(), + format_hint.expect("from_str requires a set file format"), + )) } } -- cgit v1.2.3