Skip to content

Commit

Permalink
fix: address clippy complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
Teajey committed Aug 13, 2023
1 parent dc71421 commit 4814085
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
12 changes: 4 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl<K: Serialize, V: Serialize> Serialize for DumbMap<K, V> {
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<usize, Difference>,
},
/// `source` is shorter than `target`
Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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]
Expand Down
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![doc = include_str!("../README.md")]
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use clap::Parser;

Expand All @@ -22,20 +22,20 @@ enum Error {
SerdeParse(PathBuf, serde_json::Error),
}

fn read_to_json(path: PathBuf) -> Result<serde_json::Map<String, serde_json::Value>, Error> {
fn read_to_json(path: &Path) -> Result<serde_json::Map<String, serde_json::Value>, 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<Option<String>, 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))
Expand Down

0 comments on commit 4814085

Please sign in to comment.