Use functors instead of parameters
This commit is contained in:
@@ -21,8 +21,8 @@ impl Error {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ok_or_new<T>(option: Option<T>, error_text: String, code: Option<i32>) -> Result<T> {
|
||||
Ok(option.ok_or(Error::new(error_text, code))?)
|
||||
pub fn ok_or_new<T, F>(option: Option<T>, error_text: F, code: Option<i32>) -> Result<T> where F: Fn () -> String{
|
||||
Ok(option.ok_or(Error::new(error_text(), code))?)
|
||||
}
|
||||
|
||||
fn get_exit_code(exit_code: Option<i32>) -> i32 {
|
||||
@@ -48,9 +48,9 @@ pub fn open_input(input_file: Option<PathBuf>) -> Result<Input> {
|
||||
}
|
||||
|
||||
pub fn os_str_to_string(input: &std::ffi::OsStr, name: &str) -> Result<String> {
|
||||
Ok(Error::ok_or_new(input.to_str(), format!("Converting {} to UTF-8 failed", name), None)?.to_owned())
|
||||
Ok(Error::ok_or_new(input.to_str(), ||format!("Converting {} to UTF-8 failed", name), None)?.to_owned())
|
||||
}
|
||||
|
||||
pub fn get_file_name_from_path_buf(input: &PathBuf, name: &str) -> Result<String> {
|
||||
os_str_to_string(Error::ok_or_new(input.file_name(), format!("No {} file name found", name), None)?, name)
|
||||
os_str_to_string(Error::ok_or_new(input.file_name(), ||format!("No {} file name found", name), None)?, name)
|
||||
}
|
Reference in New Issue
Block a user