From 166a4ba0ded73f34e48ec7e5572ebcd2aff36142 Mon Sep 17 00:00:00 2001 From: shimunn <> Date: Fri, 17 May 2019 19:15:50 +0200 Subject: [PATCH] applied clippy suggestions --- src/main.rs | 17 ++++++++++------- src/model.rs | 8 ++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 668b0bc..ee4e346 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ fn main() { "Hello, world! {:?}", update( &opts.repo.unwrap(), - comments.take(opts.fetch).filter_map(|c| c.ok()), + comments.take(opts.fetch).flatten(), &opts.redditor, &("reddit.com/u/".to_owned() + &opts.redditor), (opts.threshold, opts.thresholdp) @@ -34,7 +34,7 @@ fn main() { ); } -fn update<'a>( +fn update( repo: &PathBuf, current: impl IntoIterator, redditor: &str, @@ -43,7 +43,7 @@ fn update<'a>( ) -> Result> { let comment_path = |c: &Comment| { let mut p = repo.clone(); - for s in c.permalink.split("/") { + for s in c.permalink.split('/') { p.push(s); } p.set_extension("json"); @@ -55,7 +55,7 @@ fn update<'a>( let mut index = git.index()?; index.read(false)?; let (threshold, threshold_percent) = threshold; - let threshold_percent = threshold_percent as f32; + let threshold_percent = f32::from(threshold_percent); let head = || dbg!(git.find_commit(git.head()?.target().unwrap())); let mut parent = head()?; for comment in current.into_iter() { @@ -81,9 +81,12 @@ fn update<'a>( _ => true, }) .collect::>(); - if delta.len() > 0 { + if !delta.is_empty() { fs_write(&path, to_string_pretty(&comment)?)?; - commit_msg = delta.iter().map(|d| d.to_string()).collect::>()[..].join("\n"); + for msg in delta.iter() { + commit_msg.push_str(&msg.to_string()); + commit_msg.push('\n'); + } //index.update_all(vec![&path], None)?; updated += 1; true @@ -103,7 +106,7 @@ fn update<'a>( let tree_id = index.write_tree()?; let tree = git.find_tree(tree_id)?; - let time = commit_timestamp.unwrap_or(comment.last_update()); + let time = commit_timestamp.unwrap_or_else(|| comment.last_update()); let sig_backdate = Signature::new(sig.name().unwrap(), sig.email().unwrap(), &{ let dur = dbg!(time).duration_since(UNIX_EPOCH).unwrap(); diff --git a/src/model.rs b/src/model.rs index d57f6bd..018ad59 100644 --- a/src/model.rs +++ b/src/model.rs @@ -46,8 +46,8 @@ impl fmt::Display for CommentDelta { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use CommentDelta::*; match self { - Votes(d) if d > &0 => write!(f, "Received +{} upvotes", d), - Votes(d) if d < &0 => write!(f, "Received {} downvotes", d), + Votes(d) if *d > 0 => write!(f, "Received +{} upvotes", d), + Votes(d) if *d < 0 => write!(f, "Received {} downvotes", d), Votes(_) => write!(f, "You shouln't see this one, if you do check the source"), Content => write!(f, "Edited"), New => write!(f, "Created"), @@ -103,7 +103,7 @@ impl Comments { pub fn new(url: T) -> Comments { let url = url.to_string(); Comments { - url: url, + url, continuation: None, buffer: None, no_it: 0, @@ -127,7 +127,7 @@ impl Iterator for Comments { let comment_json: Value = serde_json::from_str(&comment_json)?; let data: &Value = &comment_json["data"]; let continuation: Option = match &data["after"] { - Value::String(after) if after.len() > 0 => Some(after.clone()), + Value::String(after) if !after.is_empty() => Some(after.clone()), _ => None, }; //Kinda ugly .clone()