[No-auto] lib/core/rt: Fix Clippy warnings

Signed-off-by: flip1995 <hello@philkrones.com>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
flip1995 2019-08-27 10:18:22 +02:00 committed by Matthias Beyer
parent daddea7adf
commit 7b5f216e01
3 changed files with 18 additions and 16 deletions

View file

@ -56,11 +56,11 @@ pub fn fetch_config(searchpath: &PathBuf) -> Result<Option<Value>> {
env::var("HOME") env::var("HOME")
.map(|home| gen_vars(&PathBuf::from(home), variants.iter(), &modifier)) .map(|home| gen_vars(&PathBuf::from(home), variants.iter(), &modifier))
.unwrap_or(vec![]), .unwrap_or_else(|_| vec![]),
xdg_basedir::get_data_home() xdg_basedir::get_data_home()
.map(|data_dir| gen_vars(&data_dir, variants.iter(), &modifier)) .map(|data_dir| gen_vars(&data_dir, variants.iter(), &modifier))
.unwrap_or(vec![]), .unwrap_or_else(|_| vec![]),
]; ];
let config = vals let config = vals

View file

@ -138,17 +138,17 @@ impl Log for ImagLogger {
.render(&format!("{}", record.level()), &data) .render(&format!("{}", record.level()), &data)
.unwrap_or_else(|e| format!("Failed rendering logging data: {:?}\n", e)); .unwrap_or_else(|e| format!("Failed rendering logging data: {:?}\n", e));
let log_to_destination = |d: &LogDestination| match d { let log_to_destination = |d: &LogDestination| match *d {
&LogDestination::Stderr => { LogDestination::Stderr => {
let _ = write!(stderr(), "{}\n", logtext); 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. // if there is an error in the lock, we cannot do anything. So we ignore it here.
let _ = arc_mutex_logdest let _ = arc_mutex_logdest
.deref() .deref()
.lock() .lock()
.map(|mut logdest| { .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(); module_setting.level.unwrap_or(self.global_loglevel) >= record.level();
if set { if set {
module_setting.destinations.as_ref().map(|destinations| for d in destinations { if let Some(destinations) = &module_setting.destinations {
// If there's an error, we cannot do anything, can we? for d in destinations {
log_to_destination(&d); // If there's an error, we cannot do anything, can we?
}); log_to_destination(&d);
}
}
for d in self.global_destinations.iter() { for d in self.global_destinations.iter() {
// If there's an error, we cannot do anything, can we? // 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") .read_string("imag.logging.level")
.map_err(Error::from) .map_err(Error::from)
.context(EM::TomlQueryError)? .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))?; .and_then(|s| match_log_level_str(&s))?;
if let Some(cli_loglevel) = get_arg_loglevel(matches)? { if let Some(cli_loglevel) = get_arg_loglevel(matches)? {
@ -262,7 +264,7 @@ fn translate_destination(raw: &str) -> Result<LogDestination> {
} }
fn translate_destinations(raw: &Vec<Value>) -> Result<Vec<LogDestination>> { fn translate_destinations(raw: &[Value]) -> Result<Vec<LogDestination>> {
raw.iter() raw.iter()
.map(|val| { .map(|val| {
val.as_str() val.as_str()
@ -289,7 +291,7 @@ fn aggregate_global_destinations(config: Option<&Value>)
let msg = "Type error at 'imag.logging.destinations', expected 'Array'"; let msg = "Type error at 'imag.logging.destinations', expected 'Array'";
err_msg(msg) err_msg(msg)
}) })
.and_then(translate_destinations), .and_then(|val| translate_destinations(val)),
} }
} }

View file

@ -388,7 +388,7 @@ impl<'a> Runtime<'a> {
None => Ok(None), None => Ok(None),
}) })
}) })
.or(env::var("EDITOR")) .or_else(|_| env::var("EDITOR"))
.map_err(|_| Error::from(EM::IO)) .map_err(|_| Error::from(EM::IO))
.map_dbg(|s| format!("Editing with '{}'", s)) .map_dbg(|s| format!("Editing with '{}'", s))
.and_then(|s| { .and_then(|s| {
@ -624,6 +624,6 @@ fn get_override_specs(matches: &ArgMatches) -> Vec<String> {
.map(String::from) .map(String::from)
.collect() .collect()
}) })
.unwrap_or(vec![]) .unwrap_or_else(|| vec![])
} }