archive
/
md-pdf-rs
Archived
1
Fork 0

Code format

This commit is contained in:
Jake Howard 2017-07-26 15:33:13 +01:00
parent 70c48ea9ab
commit 0e2e596071
Signed by: jake
GPG Key ID: 57AFB45680EDD477
4 changed files with 20 additions and 7 deletions

View File

@ -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));
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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)),
};
}