From 8ae689863d36f418f172c03b0dfb1909431b9786 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 20:35:45 +0200 Subject: [PATCH 01/17] Add clippy job --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index 5fc02d81..9998ac78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,14 @@ matrix: script: - cargo build --all --all-features -j 1 || exit 1 - cargo test --all --all-features -j 1 || exit 1 + - language: rust + rust: nightly + allow_failure: true + cache: + cargo: true + script: + - cargo install clippy || exit 1 + - cargo-clippy || exit 1 addons: From 488ce9fe912d7e57a0f3afbf14d01ac1cb4950b2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 20:51:27 +0200 Subject: [PATCH 02/17] Clippy fixes --- lib/etc/libimagutil/src/date.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/etc/libimagutil/src/date.rs b/lib/etc/libimagutil/src/date.rs index b1da81ed..edbd8ace 100644 --- a/lib/etc/libimagutil/src/date.rs +++ b/lib/etc/libimagutil/src/date.rs @@ -21,7 +21,7 @@ use chrono::NaiveDate; use chrono::NaiveDateTime; use chrono::format::ParseError; -pub const NAIVE_DATE_STRING_FORMAT : &'static str = "%Y-%m-%d"; +pub const NAIVE_DATE_STRING_FORMAT : &str = "%Y-%m-%d"; pub fn date_to_string(ndt: &NaiveDate) -> String { ndt.format(NAIVE_DATE_STRING_FORMAT).to_string() @@ -33,7 +33,7 @@ pub fn date_from_string(s: S) -> Result NaiveDate::parse_from_str(s.as_ref(), NAIVE_DATE_STRING_FORMAT) } -pub const NAIVE_DATETIME_STRING_FORMAT : &'static str = "%Y-%m-%d %H:%M:%S"; +pub const NAIVE_DATETIME_STRING_FORMAT : &str = "%Y-%m-%d %H:%M:%S"; pub fn datetime_to_string(ndt: &NaiveDateTime) -> String { ndt.format(NAIVE_DATETIME_STRING_FORMAT).to_string() From 775508a6ed21233b0b7da7185058d98ab31a983b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 20:56:07 +0200 Subject: [PATCH 03/17] Refactor: Use AsRef instead of String as arg type --- lib/etc/libimagutil/src/cli_validators.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/etc/libimagutil/src/cli_validators.rs b/lib/etc/libimagutil/src/cli_validators.rs index 49cee6c1..e2e9c8a5 100644 --- a/lib/etc/libimagutil/src/cli_validators.rs +++ b/lib/etc/libimagutil/src/cli_validators.rs @@ -23,27 +23,27 @@ use std::path::PathBuf; use boolinator::Boolinator; -pub fn is_existing_path(s: String) -> Result<(), String> { - PathBuf::from(s.clone()).exists().as_result((), format!("Not a File or Directory: {}", s)) +pub fn is_existing_path>(s: A) -> Result<(), String> { + PathBuf::from(s.as_ref()).exists().as_result((), format!("Not a File or Directory: {}", s.as_ref())) } -pub fn is_file(s: String) -> Result<(), String> { - PathBuf::from(s.clone()).is_file().as_result((), format!("Not a File: {}", s)) +pub fn is_file>(s: A) -> Result<(), String> { + PathBuf::from(s.as_ref()).is_file().as_result((), format!("Not a File: {}", s.as_ref())) } -pub fn is_directory(s: String) -> Result<(), String> { - PathBuf::from(s.clone()).is_dir().as_result((), format!("Not a Directory: {}", s)) +pub fn is_directory>(s: A) -> Result<(), String> { + PathBuf::from(s.as_ref()).is_dir().as_result((), format!("Not a Directory: {}", s.as_ref())) } -pub fn is_integer(s: String) -> Result<(), String> { +pub fn is_integer>(s: A) -> Result<(), String> { use std::str::FromStr; - let i : Result = FromStr::from_str(&s); - i.map(|_| ()).map_err(|_| format!("Not an integer: {}", s)) + let i : Result = FromStr::from_str(s.as_ref()); + i.map(|_| ()).map_err(|_| format!("Not an integer: {}", s.as_ref())) } -pub fn is_url(s: String) -> Result<(), String> { +pub fn is_url>(s: A) -> Result<(), String> { use url::Url; - Url::parse(&s).map(|_| ()).map_err(|_| format!("Not a URL: {}", s)) + Url::parse(s.as_ref()).map(|_| ()).map_err(|_| format!("Not a URL: {}", s.as_ref())) } From 42c4186dec1822bdd7dd9d15dca9d8611fb40246 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 20:58:02 +0200 Subject: [PATCH 04/17] Use or_else() instead of or() --- lib/etc/libimagutil/src/key_value_split.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/etc/libimagutil/src/key_value_split.rs b/lib/etc/libimagutil/src/key_value_split.rs index f1ad8c9d..b1427dc1 100644 --- a/lib/etc/libimagutil/src/key_value_split.rs +++ b/lib/etc/libimagutil/src/key_value_split.rs @@ -75,7 +75,12 @@ impl IntoKeyValue for String { .unwrap(); } R.captures(&self[..]) - .map(|c| c.name("VALUE").or(c.name("QVALUE")).map(|m| m.as_str()).unwrap_or("")) + .map(|c| { + c.name("VALUE") + .or_else(|| c.name("QVALUE")) + .map(|m| m.as_str()) + .unwrap_or("") + }) }; key.and_then(|k| { From 154c2e482b1283ce9b8c7b2ba9838d75fe107a66 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:01:51 +0200 Subject: [PATCH 05/17] Change generate_variants() helper to use base by ref --- lib/core/libimagrt/src/configuration.rs | 6 +++--- lib/etc/libimagutil/src/variants.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/core/libimagrt/src/configuration.rs b/lib/core/libimagrt/src/configuration.rs index 20892064..0706935a 100644 --- a/lib/core/libimagrt/src/configuration.rs +++ b/lib/core/libimagrt/src/configuration.rs @@ -56,12 +56,12 @@ pub fn fetch_config(searchpath: &PathBuf) -> Result { vec![ vec![searchpath.clone()], - gen_vars(searchpath.clone(), variants.clone(), &modifier), + gen_vars(searchpath, variants.clone(), &modifier), - env::var("HOME").map(|home| gen_vars(PathBuf::from(home), variants.clone(), &modifier)) + env::var("HOME").map(|home| gen_vars(&PathBuf::from(home), variants.clone(), &modifier)) .unwrap_or(vec![]), - xdg_basedir::get_data_home().map(|data_dir| gen_vars(data_dir, variants.clone(), &modifier)) + xdg_basedir::get_data_home().map(|data_dir| gen_vars(&data_dir, variants.clone(), &modifier)) .unwrap_or(vec![]), ].iter() .flatten() diff --git a/lib/etc/libimagutil/src/variants.rs b/lib/etc/libimagutil/src/variants.rs index ac56eaeb..0a456de9 100644 --- a/lib/etc/libimagutil/src/variants.rs +++ b/lib/etc/libimagutil/src/variants.rs @@ -32,12 +32,12 @@ * ``` * */ -pub fn generate_variants(base: A, modders: Vec, f: &F) +pub fn generate_variants(base: &A, modders: Vec, f: &F) -> Vec where F: Fn(&A, B) -> C { - modders.into_iter().map(|m| f(&base, m)).collect() + modders.into_iter().map(|m| f(base, m)).collect() } #[cfg(test)] @@ -49,7 +49,7 @@ mod test { fn test_variants_simple() { let base = 1; let vars = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - let res = generate_variants(base, vars, &|base, var| base + var); + let res = generate_variants(&base, vars, &|base, var| base + var); assert!(res.len() == 11, format!("Length is {} instead of 11", res.len())); assert!(res.iter().all(|i| *i > 0)); @@ -62,7 +62,7 @@ mod test { let base = PathBuf::from("/"); let vars = vec!["foo", "bar", "baz"]; - let res = generate_variants(base, vars, &|base, var| { + let res = generate_variants(&base, vars, &|base, var| { let mut base = base.clone(); base.push(var); base From 84249e3fb5865e825b3adbc59108ce5dfdc1d203 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:02:34 +0200 Subject: [PATCH 06/17] Be less verbose when constructing an object The rust compiler does some fancy things for us: It automatically finds the right fields if the name of the variable and the file is the same. Lets use that to reduce boilerplate with this patch. --- lib/core/libimagerror/src/iter.rs | 2 +- lib/core/libimagstore/src/store.rs | 11 ++++------- lib/core/libimagstore/src/storeid.rs | 6 ++---- .../libimagnotification/src/result_notification.rs | 2 +- lib/etc/libimagtimeui/src/date.rs | 6 +----- lib/etc/libimagtimeui/src/datetime.rs | 5 +---- lib/etc/libimagtimeui/src/time.rs | 6 +----- 7 files changed, 11 insertions(+), 27 deletions(-) diff --git a/lib/core/libimagerror/src/iter.rs b/lib/core/libimagerror/src/iter.rs index a25f5dca..2bca4649 100644 --- a/lib/core/libimagerror/src/iter.rs +++ b/lib/core/libimagerror/src/iter.rs @@ -143,7 +143,7 @@ pub trait TraceIterator : Iterator> + Sized { fn unwrap_with(self, f: F) -> UnwrapWith where F: FnMut(E) { - UnwrapWith { iter: self, f: f } + UnwrapWith { iter: self, f } } } diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index dd1b1f76..8a939df1 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -148,7 +148,7 @@ impl StoreEntry { } Ok(StoreEntry { - id: id, + id, file: backend.new_instance(pb), status: StoreEntryStatus::Present, }) @@ -758,10 +758,7 @@ impl<'a> FileLockEntry<'a, > { /// /// Only for internal use. fn new(store: &'a Store, entry: Entry) -> FileLockEntry<'a> { - FileLockEntry { - store: store, - entry: entry, - } + FileLockEntry { store, entry } } } @@ -883,8 +880,8 @@ impl Entry { Ok(Entry { location: loc.into_storeid()?, - header: header, - content: content, + header, + content, }) } diff --git a/lib/core/libimagstore/src/storeid.rs b/lib/core/libimagstore/src/storeid.rs index b25f2441..bf399ff3 100644 --- a/lib/core/libimagstore/src/storeid.rs +++ b/lib/core/libimagstore/src/storeid.rs @@ -80,7 +80,7 @@ impl StoreId { debug!("Building Storeid object baseless"); Ok(StoreId { base: None, - id: id + id }) } } @@ -255,9 +255,7 @@ impl Debug for StoreIdIterator { impl StoreIdIterator { pub fn new(iter: Box>) -> StoreIdIterator { - StoreIdIterator { - iter: iter, - } + StoreIdIterator { iter } } } diff --git a/lib/etc/libimagnotification/src/result_notification.rs b/lib/etc/libimagnotification/src/result_notification.rs index 20091779..497c2e4f 100644 --- a/lib/etc/libimagnotification/src/result_notification.rs +++ b/lib/etc/libimagnotification/src/result_notification.rs @@ -44,7 +44,7 @@ pub mod err { impl ErrorNotification { pub fn new(trace: usize, timeout: i32) -> ErrorNotification { let notif = Notification { - timeout: timeout, + timeout, message: String::new(), // Not used in this special case summary: "[Error]".to_owned(), urgency: Urgency::High, diff --git a/lib/etc/libimagtimeui/src/date.rs b/lib/etc/libimagtimeui/src/date.rs index 86ce468c..eb05f0fc 100644 --- a/lib/etc/libimagtimeui/src/date.rs +++ b/lib/etc/libimagtimeui/src/date.rs @@ -30,11 +30,7 @@ pub struct Date { impl Date { pub fn new(year: i32, month: u32, day: u32) -> Date { - Date { - year: year, - month: month, - day: day, - } + Date { year, month, day } } pub fn year(&self) -> i32 { diff --git a/lib/etc/libimagtimeui/src/datetime.rs b/lib/etc/libimagtimeui/src/datetime.rs index c55e8820..f0092b7f 100644 --- a/lib/etc/libimagtimeui/src/datetime.rs +++ b/lib/etc/libimagtimeui/src/datetime.rs @@ -31,10 +31,7 @@ pub struct DateTime { impl DateTime { pub fn new(date: Date, time: Time) -> DateTime { - DateTime { - date: date, - time: time - } + DateTime { date, time } } pub fn date(&self) -> &Date { diff --git a/lib/etc/libimagtimeui/src/time.rs b/lib/etc/libimagtimeui/src/time.rs index 37703edc..2e5fbb75 100644 --- a/lib/etc/libimagtimeui/src/time.rs +++ b/lib/etc/libimagtimeui/src/time.rs @@ -30,11 +30,7 @@ pub struct Time { impl Time { pub fn new(hour: u32, minute: u32, second: u32) -> Time { - Time { - hour: hour, - minute: minute, - second: second - } + Time { hour, minute, second } } pub fn hour(&self) -> u32 { From a25f650ca02d5b82a7efdd34585edfe819f9dc0f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:04:33 +0200 Subject: [PATCH 07/17] Be more ergonomic here --- lib/core/libimagerror/src/str.rs | 2 +- lib/etc/libimagutil/src/key_value_split.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/libimagerror/src/str.rs b/lib/core/libimagerror/src/str.rs index 66105d61..745a1f4b 100644 --- a/lib/core/libimagerror/src/str.rs +++ b/lib/core/libimagerror/src/str.rs @@ -25,7 +25,7 @@ pub trait ErrFromStr { impl ErrFromStr for Result { fn err_from_str(self) -> Result { - self.map_err(|e| format!("{}", e.description())) + self.map_err(|e| e.description().to_string()) } } diff --git a/lib/etc/libimagutil/src/key_value_split.rs b/lib/etc/libimagutil/src/key_value_split.rs index b1427dc1..ce9989ab 100644 --- a/lib/etc/libimagutil/src/key_value_split.rs +++ b/lib/etc/libimagutil/src/key_value_split.rs @@ -33,7 +33,7 @@ pub struct KeyValue { impl KeyValue { pub fn new(k: K, v: V) -> KeyValue { - KeyValue { k: k, v: v } + KeyValue { k, v } } pub fn key(&self) -> &K { From 67675b2ab26d5350e8d4e798320b0f0406accaca Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:05:51 +0200 Subject: [PATCH 08/17] Remove unecessary clone --- lib/etc/libimagnotification/src/result_notification.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/etc/libimagnotification/src/result_notification.rs b/lib/etc/libimagnotification/src/result_notification.rs index 497c2e4f..8f700caa 100644 --- a/lib/etc/libimagnotification/src/result_notification.rs +++ b/lib/etc/libimagnotification/src/result_notification.rs @@ -62,7 +62,7 @@ pub mod err { let mut n = RustNotification::new(); n.appname("imag"); n.summary("[Error]"); - n.urgency(urgency.clone()); + n.urgency(urgency); n.body(e.description()); try!(n.finalize().show().map(|_| ()).chain_err(|| NEK::Unknown)); From dc18e650bb2b15bd761baef39337969d89668439 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:07:10 +0200 Subject: [PATCH 09/17] Collapse nested if-else-if --- lib/core/libimagstore/src/util.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/core/libimagstore/src/util.rs b/lib/core/libimagstore/src/util.rs index e353d3f4..f09fecd8 100644 --- a/lib/core/libimagstore/src/util.rs +++ b/lib/core/libimagstore/src/util.rs @@ -52,16 +52,12 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> { if line == "---" && !header_consumed { header_consumed = true; // do not further process the line + } else if !header_consumed { + let _ = writeln!(header, "{}", line)?; + } else if iter.peek().is_some() { + let _ = writeln!(content, "{}", line)?; } else { - if !header_consumed { - let _ = writeln!(header, "{}", line)?; - } else { - if iter.peek().is_some() { - let _ = writeln!(content, "{}", line)?; - } else { - let _ = write!(content, "{}", line)?; - } - } + let _ = write!(content, "{}", line)?; } } From 44521a7c8cc77adc82b13269e24127e2ed645441 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:09:28 +0200 Subject: [PATCH 10/17] Dont use "return" keyword at end of function --- lib/core/libimagstore/src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 8a939df1..11a18c3d 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -131,7 +131,7 @@ impl Iterator for Walk { } } - return None; + None } } From 6f5590713a7855d12f8e3b5e22ba882a3c1cd9a3 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:10:43 +0200 Subject: [PATCH 11/17] Use single quotes here --- lib/core/libimagstore/src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/libimagstore/src/util.rs b/lib/core/libimagstore/src/util.rs index f09fecd8..f0efdb1b 100644 --- a/lib/core/libimagstore/src/util.rs +++ b/lib/core/libimagstore/src/util.rs @@ -46,7 +46,7 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> { let mut content = String::new(); let mut header_consumed = false; - let mut iter = buf.split("\n").skip(1).peekable(); // the first line is "---" + let mut iter = buf.split('\n').skip(1).peekable(); // the first line is "---" while let Some(line) = iter.next() { if line == "---" && !header_consumed { From 22170a0d550be53a37caa85e4f9911029688b314 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:15:19 +0200 Subject: [PATCH 12/17] Do not String::from(String) --- lib/core/libimagstore/src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/libimagstore/src/util.rs b/lib/core/libimagstore/src/util.rs index f0efdb1b..61b232a3 100644 --- a/lib/core/libimagstore/src/util.rs +++ b/lib/core/libimagstore/src/util.rs @@ -61,7 +61,7 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> { } } - Ok((Value::parse(&header)?, String::from(content))) + Ok((Value::parse(&header)?, content)) } #[cfg(test)] From f1142c414deb5d8f864a54ed383520372c8473a8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:16:55 +0200 Subject: [PATCH 13/17] Use ok_or_else() instead of ok_or() --- lib/core/libimagstore/src/configuration.rs | 2 +- lib/core/libimagstore/src/file_abstraction/inmemory.rs | 8 ++++---- lib/core/libimagstore/src/store.rs | 4 ++-- lib/core/libimagstore/src/storeid.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/core/libimagstore/src/configuration.rs b/lib/core/libimagstore/src/configuration.rs index 1ff82873..d09ef41a 100644 --- a/lib/core/libimagstore/src/configuration.rs +++ b/lib/core/libimagstore/src/configuration.rs @@ -31,7 +31,7 @@ pub fn config_implicit_store_create_allowed(config: &Option) -> Result Result<(), SE> { @@ -131,7 +131,7 @@ impl FileAbstraction for InMemoryFileAbstraction { let mut mtx = self.backend().lock().expect("Locking Mutex failed"); let backend = mtx.get_mut(); - let a = backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))?; + let a = backend.get(from).cloned().ok_or_else(|| SE::from_kind(SEK::FileNotFound))?; backend.insert(to.clone(), a); debug!("Copying: {:?} -> {:?} worked", from, to); Ok(()) @@ -142,7 +142,7 @@ impl FileAbstraction for InMemoryFileAbstraction { let mut mtx = self.backend().lock().expect("Locking Mutex failed"); let backend = mtx.get_mut(); - let a = backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))?; + let a = backend.get(from).cloned().ok_or_else(|| SE::from_kind(SEK::FileNotFound))?; backend.insert(to.clone(), a); debug!("Renaming: {:?} -> {:?} worked", from, to); Ok(()) diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 11a18c3d..6e78151f 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -1007,13 +1007,13 @@ fn has_only_tables(t: &Value) -> Result { fn has_main_section(t: &Value) -> Result { t.read("imag")? - .ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag"))) + .ok_or_else(|| SE::from_kind(SEK::ConfigKeyMissingError("imag"))) .map(Value::is_table) } fn has_imag_version_in_main_section(t: &Value) -> Result { t.read_string("imag.version")? - .ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version"))) + .ok_or_else(|| SE::from_kind(SEK::ConfigKeyMissingError("imag.version"))) .map(String::from) .map(|s| ::semver::Version::parse(&s).is_ok()) } diff --git a/lib/core/libimagstore/src/storeid.rs b/lib/core/libimagstore/src/storeid.rs index bf399ff3..2bcd9ba7 100644 --- a/lib/core/libimagstore/src/storeid.rs +++ b/lib/core/libimagstore/src/storeid.rs @@ -116,7 +116,7 @@ impl StoreId { .unwrap_or_else(|| self.id.clone()) .to_str() .map(String::from) - .ok_or(SE::from_kind(SEK::StoreIdHandlingError)) + .ok_or_else(|| SE::from_kind(SEK::StoreIdHandlingError)) } /// Returns the components of the `id` part of the StoreId object. From bf363c474834f9692b9088a2238b8f2c16603eb2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:24:56 +0200 Subject: [PATCH 14/17] Use "if let" if matching on a single pattern --- lib/core/libimagstore/src/store.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 6e78151f..57a4a7dd 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -793,12 +793,9 @@ impl<'a> Drop for FileLockEntry<'a> { fn drop(&mut self) { use libimagerror::trace::trace_error_dbg; trace!("Dropping: {:?} - from FileLockEntry::drop()", self.get_location()); - match self.store._update(self, true) { - Err(e) => { - trace_error_dbg(&e); - if_cfg_panic!("ERROR WHILE DROPPING: {:?}", e); - }, - Ok(_) => { }, + if let Err(e) = self.store._update(self, true) { + trace_error_dbg(&e); + if_cfg_panic!("ERROR WHILE DROPPING: {:?}", e); } } } From 6a34e7a8fdf71a1905ea42398b1ec95f8e0e952c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:27:59 +0200 Subject: [PATCH 15/17] Derive Default for FSFileAbstraction, reduces boilerplate --- lib/core/libimagstore/src/file_abstraction/fs.rs | 11 ++--------- lib/core/libimagstore/src/store.rs | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/core/libimagstore/src/file_abstraction/fs.rs b/lib/core/libimagstore/src/file_abstraction/fs.rs index c1d5c4c1..a41a2239 100644 --- a/lib/core/libimagstore/src/file_abstraction/fs.rs +++ b/lib/core/libimagstore/src/file_abstraction/fs.rs @@ -105,15 +105,8 @@ impl FileAbstractionInstance for FSFileAbstractionInstance { /// `FSFileAbstraction` state type /// /// A lazy file is either absent, but a path to it is available, or it is present. -#[derive(Debug)] -pub struct FSFileAbstraction { -} - -impl FSFileAbstraction { - pub fn new() -> FSFileAbstraction { - FSFileAbstraction { } - } -} +#[derive(Debug, Default)] +pub struct FSFileAbstraction {} impl FileAbstraction for FSFileAbstraction { diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 57a4a7dd..039b6b3f 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -235,7 +235,7 @@ impl Store { /// - On success: Store object /// pub fn new(location: PathBuf, store_config: &Option) -> Result { - let backend = Box::new(FSFileAbstraction::new()); + let backend = Box::new(FSFileAbstraction::default()); Store::new_with_backend(location, store_config, backend) } From ea80a5a09b5851a4dce9984be3847bd580f7af77 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Apr 2018 21:32:22 +0200 Subject: [PATCH 16/17] Derive Default for InMemoryFileAbstraction, remove constructor --- lib/core/libimagrt/src/runtime.rs | 2 +- lib/core/libimagstore/src/file_abstraction/inmemory.rs | 8 +------- lib/core/libimagstore/src/file_abstraction/mod.rs | 6 +++--- lib/core/libimagstore/src/store.rs | 6 +++--- lib/domain/libimagtimetrack/src/iter/mod.rs | 2 +- lib/entry/libimagentrycategory/src/register.rs | 2 +- lib/entry/libimagentrydatetime/src/datetime.rs | 2 +- lib/entry/libimagentrygps/src/entry.rs | 2 +- lib/entry/libimagentrylink/src/external.rs | 2 +- lib/entry/libimagentrylink/src/internal.rs | 2 +- lib/entry/libimagentrymarkdown/src/processor.rs | 2 +- 11 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs index 994bfa5b..8766cda7 100644 --- a/lib/core/libimagrt/src/runtime.rs +++ b/lib/core/libimagrt/src/runtime.rs @@ -132,7 +132,7 @@ impl<'a> Runtime<'a> { let store_result = if cli_app.use_inmemory_fs() { Store::new_with_backend(storepath, &config, - Box::new(InMemoryFileAbstraction::new())) + Box::new(InMemoryFileAbstraction::default())) } else { Store::new(storepath, &config) }; diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs index d3445b54..efe0c4f4 100644 --- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs +++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs @@ -87,19 +87,13 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance { } } -#[derive(Debug)] +#[derive(Debug, Default)] pub struct InMemoryFileAbstraction { virtual_filesystem: Backend, } impl InMemoryFileAbstraction { - pub fn new() -> InMemoryFileAbstraction { - InMemoryFileAbstraction { - virtual_filesystem: Arc::new(Mutex::new(RefCell::new(HashMap::new()))), - } - } - pub fn backend(&self) -> &Backend { &self.virtual_filesystem } diff --git a/lib/core/libimagstore/src/file_abstraction/mod.rs b/lib/core/libimagstore/src/file_abstraction/mod.rs index b6ca5e00..893b8ca2 100644 --- a/lib/core/libimagstore/src/file_abstraction/mod.rs +++ b/lib/core/libimagstore/src/file_abstraction/mod.rs @@ -104,7 +104,7 @@ mod test { #[test] fn lazy_file() { - let fs = InMemoryFileAbstraction::new(); + let fs = InMemoryFileAbstraction::default(); let mut path = PathBuf::from("tests"); path.set_file_name("test1"); @@ -124,7 +124,7 @@ Hello World"#, env!("CARGO_PKG_VERSION"))).unwrap(); #[test] fn lazy_file_multiline() { - let fs = InMemoryFileAbstraction::new(); + let fs = InMemoryFileAbstraction::default(); let mut path = PathBuf::from("tests"); path.set_file_name("test1"); @@ -145,7 +145,7 @@ baz"#, env!("CARGO_PKG_VERSION"))).unwrap(); #[test] fn lazy_file_multiline_trailing_newlines() { - let fs = InMemoryFileAbstraction::new(); + let fs = InMemoryFileAbstraction::default(); let mut path = PathBuf::from("tests"); path.set_file_name("test1"); diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 039b6b3f..5a7868a9 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -1176,7 +1176,7 @@ mod store_tests { use file_abstraction::InMemoryFileAbstraction; pub fn get_store() -> Store { - let backend = Box::new(InMemoryFileAbstraction::new()); + let backend = Box::new(InMemoryFileAbstraction::default()); Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap() } @@ -1361,7 +1361,7 @@ mod store_tests { use file_abstraction::InMemoryFileAbstraction; let mut store = { - let backend = InMemoryFileAbstraction::new(); + let backend = InMemoryFileAbstraction::default(); let backend = Box::new(backend); Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap() @@ -1377,7 +1377,7 @@ mod store_tests { } { - let other_backend = InMemoryFileAbstraction::new(); + let other_backend = InMemoryFileAbstraction::default(); let other_backend = Box::new(other_backend); assert!(store.reset_backend(other_backend).is_ok()) diff --git a/lib/domain/libimagtimetrack/src/iter/mod.rs b/lib/domain/libimagtimetrack/src/iter/mod.rs index ffe212c7..f0648ce2 100644 --- a/lib/domain/libimagtimetrack/src/iter/mod.rs +++ b/lib/domain/libimagtimetrack/src/iter/mod.rs @@ -37,7 +37,7 @@ mod test { use std::path::PathBuf; use libimagstore::file_abstraction::InMemoryFileAbstraction; - let backend = Box::new(InMemoryFileAbstraction::new()); + let backend = Box::new(InMemoryFileAbstraction::default()); Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap() } diff --git a/lib/entry/libimagentrycategory/src/register.rs b/lib/entry/libimagentrycategory/src/register.rs index 88c3e645..aa75ab4f 100644 --- a/lib/entry/libimagentrycategory/src/register.rs +++ b/lib/entry/libimagentrycategory/src/register.rs @@ -127,7 +127,7 @@ mod tests { pub fn get_store() -> Store { use libimagstore::store::InMemoryFileAbstraction; - let backend = Box::new(InMemoryFileAbstraction::new()); + let backend = Box::new(InMemoryFileAbstraction::default()); Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap() } diff --git a/lib/entry/libimagentrydatetime/src/datetime.rs b/lib/entry/libimagentrydatetime/src/datetime.rs index 8d6217e3..6eb6683d 100644 --- a/lib/entry/libimagentrydatetime/src/datetime.rs +++ b/lib/entry/libimagentrydatetime/src/datetime.rs @@ -207,7 +207,7 @@ mod tests { pub fn get_store() -> Store { use libimagstore::store::InMemoryFileAbstraction; - let backend = Box::new(InMemoryFileAbstraction::new()); + let backend = Box::new(InMemoryFileAbstraction::default()); Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap() } diff --git a/lib/entry/libimagentrygps/src/entry.rs b/lib/entry/libimagentrygps/src/entry.rs index 7478f2a1..37acb075 100644 --- a/lib/entry/libimagentrygps/src/entry.rs +++ b/lib/entry/libimagentrygps/src/entry.rs @@ -113,7 +113,7 @@ mod tests { fn get_store() -> Store { use libimagstore::file_abstraction::InMemoryFileAbstraction; - let backend = Box::new(InMemoryFileAbstraction::new()); + let backend = Box::new(InMemoryFileAbstraction::default()); Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap() } diff --git a/lib/entry/libimagentrylink/src/external.rs b/lib/entry/libimagentrylink/src/external.rs index 2e9cbade..4d7d48bc 100644 --- a/lib/entry/libimagentrylink/src/external.rs +++ b/lib/entry/libimagentrylink/src/external.rs @@ -416,7 +416,7 @@ mod tests { pub fn get_store() -> Store { use libimagstore::file_abstraction::InMemoryFileAbstraction; - let backend = Box::new(InMemoryFileAbstraction::new()); + let backend = Box::new(InMemoryFileAbstraction::default()); Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap() } diff --git a/lib/entry/libimagentrylink/src/internal.rs b/lib/entry/libimagentrylink/src/internal.rs index f3eece08..e7c06fd7 100644 --- a/lib/entry/libimagentrylink/src/internal.rs +++ b/lib/entry/libimagentrylink/src/internal.rs @@ -784,7 +784,7 @@ mod test { pub fn get_store() -> Store { use libimagstore::file_abstraction::InMemoryFileAbstraction; - let backend = Box::new(InMemoryFileAbstraction::new()); + let backend = Box::new(InMemoryFileAbstraction::default()); Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap() } diff --git a/lib/entry/libimagentrymarkdown/src/processor.rs b/lib/entry/libimagentrymarkdown/src/processor.rs index 351ba321..f9b085a5 100644 --- a/lib/entry/libimagentrymarkdown/src/processor.rs +++ b/lib/entry/libimagentrymarkdown/src/processor.rs @@ -243,7 +243,7 @@ mod tests { pub fn get_store() -> Store { use libimagstore::file_abstraction::InMemoryFileAbstraction; - let fs = InMemoryFileAbstraction::new(); + let fs = InMemoryFileAbstraction::default(); Store::new_with_backend(PathBuf::from("/"), &None, Box::new(fs)).unwrap() } From 2b250bd8c80f58fc1494a652a134a60558c414c6 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 25 Apr 2018 21:39:56 +0200 Subject: [PATCH 17/17] Revert "Add clippy job" This reverts commit 8ae689863d36f418f172c03b0dfb1909431b9786. --- .travis.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9998ac78..5fc02d81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,14 +36,6 @@ matrix: script: - cargo build --all --all-features -j 1 || exit 1 - cargo test --all --all-features -j 1 || exit 1 - - language: rust - rust: nightly - allow_failure: true - cache: - cargo: true - script: - - cargo install clippy || exit 1 - - cargo-clippy || exit 1 addons: