diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs index 62233be9..f765739f 100644 --- a/lib/core/libimagrt/src/configuration.rs +++ b/lib/core/libimagrt/src/configuration.rs @@ -56,11 +56,11 @@ pub fn fetch_config(searchpath: &PathBuf) -> Result> { env::var("HOME") .map(|home| gen_vars(&PathBuf::from(home), variants.iter(), &modifier)) - .unwrap_or(vec![]), + .unwrap_or_else(|_| vec![]), xdg_basedir::get_data_home() .map(|data_dir| gen_vars(&data_dir, variants.iter(), &modifier)) - .unwrap_or(vec![]), + .unwrap_or_else(|_| vec![]), ]; let config = vals diff --git a/lib/core/libimagrt/src/logger.rs b/lib/core/libimagrt/src/logger.rs index 1f2da580..0313be1d 100644 --- a/lib/core/libimagrt/src/logger.rs +++ b/lib/core/libimagrt/src/logger.rs @@ -138,17 +138,17 @@ impl Log for ImagLogger { .render(&format!("{}", record.level()), &data) .unwrap_or_else(|e| format!("Failed rendering logging data: {:?}\n", e)); - let log_to_destination = |d: &LogDestination| match d { - &LogDestination::Stderr => { - let _ = write!(stderr(), "{}\n", logtext); + let log_to_destination = |d: &LogDestination| match *d { + LogDestination::Stderr => { + let _ = writeln!(stderr(), "{}", logtext); }, - &LogDestination::File(ref arc_mutex_logdest) => { + LogDestination::File(ref arc_mutex_logdest) => { // if there is an error in the lock, we cannot do anything. So we ignore it here. let _ = arc_mutex_logdest .deref() .lock() .map(|mut logdest| { - write!(logdest, "{}\n", logtext) + writeln!(logdest, "{}", logtext) }); } }; @@ -169,10 +169,12 @@ impl Log for ImagLogger { module_setting.level.unwrap_or(self.global_loglevel) >= record.level(); if set { - module_setting.destinations.as_ref().map(|destinations| for d in destinations { - // If there's an error, we cannot do anything, can we? - log_to_destination(&d); - }); + if let Some(destinations) = &module_setting.destinations { + for d in destinations { + // If there's an error, we cannot do anything, can we? + log_to_destination(&d); + } + } for d in self.global_destinations.iter() { // If there's an error, we cannot do anything, can we? @@ -225,7 +227,7 @@ fn aggregate_global_loglevel(matches: &ArgMatches, config: Option<&Value>) -> Re .read_string("imag.logging.level") .map_err(Error::from) .context(EM::TomlQueryError)? - .ok_or(err_msg("Global log level config missing")) + .ok_or_else(|| err_msg("Global log level config missing")) .and_then(|s| match_log_level_str(&s))?; if let Some(cli_loglevel) = get_arg_loglevel(matches)? { @@ -262,7 +264,7 @@ fn translate_destination(raw: &str) -> Result { } -fn translate_destinations(raw: &Vec) -> Result> { +fn translate_destinations(raw: &[Value]) -> Result> { raw.iter() .map(|val| { val.as_str() @@ -289,7 +291,7 @@ fn aggregate_global_destinations(config: Option<&Value>) let msg = "Type error at 'imag.logging.destinations', expected 'Array'"; err_msg(msg) }) - .and_then(translate_destinations), + .and_then(|val| translate_destinations(val)), } } diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs index 4bbca09b..e593fff7 100644 --- a/lib/core/libimagrt/src/runtime.rs +++ b/lib/core/libimagrt/src/runtime.rs @@ -388,7 +388,7 @@ impl<'a> Runtime<'a> { None => Ok(None), }) }) - .or(env::var("EDITOR")) + .or_else(|_| env::var("EDITOR")) .map_err(|_| Error::from(EM::IO)) .map_dbg(|s| format!("Editing with '{}'", s)) .and_then(|s| { @@ -624,6 +624,6 @@ fn get_override_specs(matches: &ArgMatches) -> Vec { .map(String::from) .collect() }) - .unwrap_or(vec![]) + .unwrap_or_else(|| vec![]) }