From 481408595435260aeb83d81178bc78f241a9c255 Mon Sep 17 00:00:00 2001 From: Teajey <21069848+Teajey@users.noreply.github.com> Date: Sun, 13 Aug 2023 12:11:09 +0100 Subject: [PATCH] fix: address clippy complaints --- src/lib.rs | 12 ++++-------- src/main.rs | 14 +++++++------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ddb1c6f..59f15da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,7 @@ impl Serialize for DumbMap { pub enum ArrayDifference { /// `source` and `target` are the same length, but some values of the same indices are different PairsOnly { + /// differing pairs that appear in the overlapping indices of `source` and `target` different_pairs: DumbMap, }, /// `source` is shorter than `target` @@ -105,9 +106,8 @@ pub fn arrays( let mut different_pairs = vec![]; while let (Some(_), Some(_)) = (source_iter.peek(), target_iter.peek()) { - let ((i, source), target) = match (source_iter.next(), target_iter.next()) { - (Some(source), Some(target)) => (source, target), - _ => unreachable!("checked by peek()"), + let (Some((i, source)), Some(target)) = (source_iter.next(), target_iter.next()) else { + unreachable!("checked by peek()"); }; different_pairs.push(values(source, target).map(|diff| (i, diff))); } @@ -135,11 +135,7 @@ pub fn arrays( }); } - if let Some(different_pairs) = different_pairs { - Some(ArrayDifference::PairsOnly { different_pairs }) - } else { - None - } + different_pairs.map(|different_pairs| ArrayDifference::PairsOnly { different_pairs }) } #[must_use] diff --git a/src/main.rs b/src/main.rs index 31c31d5..a45bd76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ #![doc = include_str!("../README.md")] -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use clap::Parser; @@ -22,20 +22,20 @@ enum Error { SerdeParse(PathBuf, serde_json::Error), } -fn read_to_json(path: PathBuf) -> Result, Error> { +fn read_to_json(path: &Path) -> Result, Error> { serde_json::from_str( - std::fs::read_to_string(&path) - .map_err(|err| Error::FileRead(path.clone(), err))? + std::fs::read_to_string(path) + .map_err(|err| Error::FileRead(path.to_path_buf(), err))? .as_str(), ) - .map_err(|err| Error::SerdeParse(path.clone(), err)) + .map_err(|err| Error::SerdeParse(path.to_path_buf(), err)) } fn run() -> Result, Error> { let args = Args::parse(); - let source_json = read_to_json(args.source_json)?; - let target_json = read_to_json(args.target_json)?; + let source_json = read_to_json(args.source_json.as_path())?; + let target_json = read_to_json(args.target_json.as_path())?; let possible_pretty_diff = serde_json_diff::objects(source_json, target_json) .map(|diff| serde_json::to_string_pretty(&diff))