diff --git a/src/diffs.rs b/src/diffs.rs index 69113d8e6..272ec353f 100644 --- a/src/diffs.rs +++ b/src/diffs.rs @@ -195,7 +195,7 @@ pub fn added(differences: &[Change]) -> Vec { differences .iter() .filter(|c| c.kind == ChangeKind::Add) - .map(|c| *c) + .copied() .collect() } @@ -203,7 +203,7 @@ pub fn removed(differences: &[Change]) -> Vec { differences .iter() .filter(|c| c.kind == ChangeKind::Remove) - .map(|c| *c) + .copied() .collect() } diff --git a/src/lines.rs b/src/lines.rs index 2edb736dc..164e75118 100644 --- a/src/lines.rs +++ b/src/lines.rs @@ -21,7 +21,7 @@ pub struct LineNumber { impl LineNumber { pub fn from(number: usize) -> LineNumber { - LineNumber { number: number } + LineNumber { number } } } @@ -59,9 +59,7 @@ impl NewlinePositions { positions.push(0); positions.extend(&newlines); - NewlinePositions { - positions: positions, - } + NewlinePositions { positions } } pub fn from_offset(self: &NewlinePositions, offset: usize) -> LinePosition { @@ -326,7 +324,7 @@ pub fn enforce_length(s: &str, line_length: usize) -> String { if line.len() > line_length { // Truncate. result.push_str(&line[0..line_length]); - result.push_str("\n"); + result.push('\n'); } else { // Pad with spaces. result.push_str(&format!("{:width$}\n", line, width = line_length)); diff --git a/src/main.rs b/src/main.rs index 1557a2075..ed7da8d04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -use term_size; - mod diffs; mod language; mod lines; @@ -13,14 +11,13 @@ use clap::{App, Arg}; use colored::*; use std::collections::HashMap; use std::fs; -use std::iter::FromIterator; fn term_width() -> Option { term_size::dimensions().map(|(w, _)| w) } fn index_map(lines: &[MatchedLine]) -> HashMap { - HashMap::from_iter(lines.iter().map(|ml| (ml.line.number, *ml))) + lines.into_iter().map(|ml| (ml.line.number, *ml)).collect() } /// Vertically concat the desired lines of `left` and `right`, lining @@ -67,7 +64,7 @@ fn filter_concat( result.push_str(left_str_lines[left_i]); result.push_str(spacer); result.push_str(right_str_lines[right_i]); - result.push_str("\n"); + result.push('\n'); left_i += 1; right_i += 1; @@ -83,7 +80,7 @@ fn filter_concat( // There's no matching line of code on the other // side, so just print this side. result.push_str(left_str_lines[left_i]); - result.push_str("\n"); + result.push('\n'); left_i += 1; } @@ -98,7 +95,7 @@ fn filter_concat( result.push_str(&" ".repeat(max_left_length)); result.push_str(spacer); result.push_str(right_str_lines[right_i]); - result.push_str("\n"); + result.push('\n'); right_i += 1; } @@ -119,7 +116,7 @@ fn filter_concat( fn read_or_die(path: &str) -> String { match fs::read_to_string(path) { - Ok(src) => src.to_owned(), + Ok(src) => src, Err(e) => { match e.kind() { std::io::ErrorKind::NotFound => {