Code format
This commit is contained in:
parent
70c48ea9ab
commit
0e2e596071
4 changed files with 20 additions and 7 deletions
|
@ -32,7 +32,8 @@ impl Config {
|
|||
|
||||
pub fn get_config() -> Result<Config, String> {
|
||||
let config_str = try!(read::read());
|
||||
let config = try!(result_prefix(serde_yaml::from_str(&config_str), "Config Parse Error".into()));
|
||||
let config =
|
||||
try!(result_prefix(serde_yaml::from_str(&config_str), "Config Parse Error".into()));
|
||||
try!(result_prefix(validate::validate(&config), "Config Validation Error".into()));
|
||||
return Ok(Config::new(config));
|
||||
}
|
||||
|
|
|
@ -16,9 +16,15 @@ fn get_config_path() -> PathBuf {
|
|||
|
||||
pub fn read() -> Result<String, String> {
|
||||
let config_path = get_config_path();
|
||||
let mut config_file = try!(result_override(File::open(&config_path), format!("Unable to find config file at {}", config_path.display())));
|
||||
let mut config_file = try!(result_override(
|
||||
File::open(&config_path),
|
||||
format!("Unable to find config file at {}", config_path.display())
|
||||
));
|
||||
let mut contents = String::new();
|
||||
try!(result_override(config_file.read_to_string(&mut contents), format!("Failed to read config file at {}.", config_path.display())));
|
||||
try!(result_override(
|
||||
config_file.read_to_string(&mut contents),
|
||||
format!("Failed to read config file at {}.", config_path.display())
|
||||
));
|
||||
return Ok(contents);
|
||||
}
|
||||
|
||||
|
|
10
src/input.rs
10
src/input.rs
|
@ -7,8 +7,14 @@ use utils::result_override;
|
|||
pub fn read_input_files(files: Vec<PathBuf>) -> Result<String, String> {
|
||||
let mut input = String::new();
|
||||
for input_file_path in files.iter() {
|
||||
let mut input_file = try!(result_override(File::open(input_file_path), format!("Failed to open input file {}.", input_file_path.display())));
|
||||
try!(result_override(input_file.read_to_string(&mut input), format!("Failed to read input file {}.", input_file_path.display())));
|
||||
let mut input_file = try!(result_override(
|
||||
File::open(input_file_path),
|
||||
format!("Failed to open input file {}.", input_file_path.display())
|
||||
));
|
||||
try!(result_override(
|
||||
input_file.read_to_string(&mut input),
|
||||
format!("Failed to read input file {}.", input_file_path.display())
|
||||
));
|
||||
}
|
||||
return Ok(input);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::fmt::Debug;
|
|||
pub fn result_override<T, E: Debug>(r: Result<T, E>, msg: String) -> Result<T, String> {
|
||||
return match r {
|
||||
Ok(t) => Ok(t),
|
||||
Err(_) => Err(msg)
|
||||
Err(_) => Err(msg),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,6 @@ pub fn result_override<T, E: Debug>(r: Result<T, E>, msg: String) -> Result<T, S
|
|||
pub fn result_prefix<T, E: Debug>(r: Result<T, E>, prefix: String) -> Result<T, String> {
|
||||
return match r {
|
||||
Ok(t) => Ok(t),
|
||||
Err(e) => Err(format!("{}: {:?}", prefix, e))
|
||||
Err(e) => Err(format!("{}: {:?}", prefix, e)),
|
||||
};
|
||||
}
|
||||
|
|
Reference in a new issue