From a2d3a8cffca2d790f272f9e4b70db23389f434f0 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 27 Aug 2019 10:03:08 +0200 Subject: [No-auto] bin/core/store: Fix Clippy warnings Signed-off-by: flip1995 Signed-off-by: Matthias Beyer --- bin/core/imag-store/src/retrieve.rs | 30 ++++++++++++++---------------- bin/core/imag-store/src/update.rs | 9 ++++----- bin/core/imag-store/src/util.rs | 18 ++++++++---------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/bin/core/imag-store/src/retrieve.rs b/bin/core/imag-store/src/retrieve.rs index 06a0612f..a84d39d7 100644 --- a/bin/core/imag-store/src/retrieve.rs +++ b/bin/core/imag-store/src/retrieve.rs @@ -31,24 +31,22 @@ use libimagerror::exit::ExitUnwrap; use libimagutil::debug_result::*; pub fn retrieve(rt: &Runtime) { - rt.cli() - .subcommand_matches("retrieve") - .map(|scmd| { - // unwrap() is safe as arg is required - let id = scmd.value_of("id").unwrap(); - let path = PathBuf::from(id); - let path = StoreId::new(path).map_err_trace_exit_unwrap(); - debug!("path = {:?}", path); + if let Some(scmd) = rt.cli().subcommand_matches("retrieve") { + // unwrap() is safe as arg is required + let id = scmd.value_of("id").unwrap(); + let path = PathBuf::from(id); + let path = StoreId::new(path).map_err_trace_exit_unwrap(); + debug!("path = {:?}", path); - rt.store() - .retrieve(path.clone()) - .map(|e| print_entry(rt, scmd, e)) - .map_dbg_str("No entry") - .map_dbg(|e| format!("{:?}", e)) - .map_err_trace_exit_unwrap(); + rt.store() + .retrieve(path.clone()) + .map(|e| print_entry(rt, scmd, e)) + .map_dbg_str("No entry") + .map_dbg(|e| format!("{:?}", e)) + .map_err_trace_exit_unwrap(); - rt.report_touched(&path).unwrap_or_exit(); - }); + rt.report_touched(&path).unwrap_or_exit(); + } } pub fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) { diff --git a/bin/core/imag-store/src/update.rs b/bin/core/imag-store/src/update.rs index 595b7b13..fad5b3f7 100644 --- a/bin/core/imag-store/src/update.rs +++ b/bin/core/imag-store/src/update.rs @@ -39,11 +39,10 @@ pub fn update(rt: &Runtime) { { let e = locked_e.deref_mut(); - scmd.value_of("content") - .map(|new_content| { - *e.get_content_mut() = String::from(new_content); - debug!("New content set"); - }); + if let Some(new_content) = scmd.value_of("content") { + *e.get_content_mut() = String::from(new_content); + debug!("New content set"); + } *e.get_header_mut() = build_toml_header(scmd, e.get_header().clone()); debug!("New header set"); diff --git a/bin/core/imag-store/src/util.rs b/bin/core/imag-store/src/util.rs index c1dcc8d3..8f731d1d 100644 --- a/bin/core/imag-store/src/util.rs +++ b/bin/core/imag-store/src/util.rs @@ -40,10 +40,8 @@ pub fn build_toml_header(matches: &ArgMatches, mut header: Value) -> Value { let (key, value) = tpl.into(); debug!("Splitting: {:?}", key); let mut split = key.split('.'); - match (split.next(), &mut header) { - (Some(cur), &mut Value::Table(ref mut hdr)) => - insert_key_into(String::from(cur), &mut split, Cow::Owned(value), hdr), - _ => { } + if let (Some(cur), &mut Value::Table(ref mut hdr)) = (split.next(), &mut header) { + insert_key_into(String::from(cur), &mut split, Cow::Owned(value), hdr); } } } @@ -58,27 +56,27 @@ fn insert_key_into<'a>(current: String, map: &mut Map) { let next = rest_path.next(); - if next.is_none() { - debug!("Inserting into {:?} = {:?}", current, value); - map.insert(current, parse_value(value)); - } else { + if let Some(next) = next { debug!("Inserting into {:?} ... = {:?}", current, value); match map.entry(current) { Entry::Occupied(ref mut e) => { match *e.get_mut() { Value::Table(ref mut t) => { - insert_key_into(String::from(next.unwrap()), rest_path, value, t); + insert_key_into(String::from(next), rest_path, value, t); }, _ => unreachable!(), } }, Entry::Vacant(v) => { v.insert(Value::Table( { let mut submap = Map::new(); - insert_key_into(String::from(next.unwrap()), rest_path, value, &mut submap); + insert_key_into(String::from(next), rest_path, value, &mut submap); debug!("Inserting submap = {:?}", submap); submap })); } } + } else { + debug!("Inserting into {:?} = {:?}", current, value); + map.insert(current, parse_value(value)); } } -- cgit v1.2.3