summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflip1995 <hello@philkrones.com>2019-08-27 10:18:22 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-08-28 18:18:41 +0200
commit7b5f216e019e0bfd82dc3d27e985bea3ff5c6d3a (patch)
treeb4f7dcd39b22774dde3926414f388f409489ae34
parentdaddea7adf8514178b492fe424098ef2bb1e7a3a (diff)
downloadimag-7b5f216e019e0bfd82dc3d27e985bea3ff5c6d3a.zip
imag-7b5f216e019e0bfd82dc3d27e985bea3ff5c6d3a.tar.gz
[No-auto] lib/core/rt: Fix Clippy warnings
Signed-off-by: flip1995 <hello@philkrones.com> Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/core/libimagrt/src/configuration.rs4
-rw-r--r--lib/core/libimagrt/src/logger.rs26
-rw-r--r--lib/core/libimagrt/src/runtime.rs4
3 files changed, 18 insertions, 16 deletions
diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs
index 62233be..f765739 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<Option<Value>> {
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 1f2da58..0313be1 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<LogDestination> {
}
-fn translate_destinations(raw: &Vec<Value>) -> Result<Vec<LogDestination>> {
+fn translate_destinations(raw: &[Value]) -> Result<Vec<LogDestination>> {
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 4bbca09..e593fff 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<String> {
.map(String::from)
.collect()
})
- .unwrap_or(vec![])
+ .unwrap_or_else(|| vec![])
}