From 14ae13c88e1345cf56e0b749d74f4073405b9ec2 Mon Sep 17 00:00:00 2001
From: Louis Capitanchik <contact@louiscap.co>
Date: Tue, 7 Feb 2023 21:01:18 +0000
Subject: [PATCH] Apply clippy lints

---
 src/cli_args.rs          |   6 +-
 src/commands/extrude.rs  |   2 +-
 src/commands/palette.rs  |   3 +-
 src/commands/pipeline.rs | 134 +++++++++++++++++++--------------------
 src/commands/remap.rs    |   2 +-
 src/main.rs              |   3 +-
 src/utils.rs             |   1 -
 7 files changed, 71 insertions(+), 80 deletions(-)

diff --git a/src/cli_args.rs b/src/cli_args.rs
index 1177319..717b77c 100644
--- a/src/cli_args.rs
+++ b/src/cli_args.rs
@@ -1,10 +1,10 @@
-use clap::{Parser, Subcommand};
+use clap::Parser;
 use serde::{Deserialize, Serialize};
 
 // use crate::commands::{calculate_mapping, execute_pipeline, extrude, flip, palette, remap_image, rescale, rotate, write_palette, FlipDirection, RotateDegree, Rotate};
 use crate::commands::{Extrude, Flip, Palette, Pipeline, Remap, Rotate, Scale};
-use crate::format::PaletteFormat;
-use crate::{load_image, Format};
+
+use crate::load_image;
 
 /// Crunch is a set of utilities for quickly and easily processing a batch of files, either directly
 /// or by defining pipelines
diff --git a/src/commands/extrude.rs b/src/commands/extrude.rs
index 4aa0a47..6559cea 100644
--- a/src/commands/extrude.rs
+++ b/src/commands/extrude.rs
@@ -1,4 +1,4 @@
-use crate::utils::{OutputFormat, RgbaOutputFormat, SpriteData};
+use crate::utils::{RgbaOutputFormat, SpriteData};
 use clap::Parser;
 use image::{GenericImage, GenericImageView, Pixel, Rgba, RgbaImage};
 use num_traits::cast::ToPrimitive;
diff --git a/src/commands/palette.rs b/src/commands/palette.rs
index 60c9003..167b541 100644
--- a/src/commands/palette.rs
+++ b/src/commands/palette.rs
@@ -2,9 +2,8 @@ use clap::Parser;
 use std::cmp::{min, Ordering};
 use std::collections::hash_map::RandomState;
 use std::collections::{HashMap, HashSet};
-use std::fmt::{Formatter, LowerHex, UpperHex};
+
 use std::io::Write;
-use std::path::Path;
 
 use deltae::{Delta, LabValue, DE2000};
 use image::{GenericImage, Pixel, Rgba};
diff --git a/src/commands/pipeline.rs b/src/commands/pipeline.rs
index a538fc5..db80112 100644
--- a/src/commands/pipeline.rs
+++ b/src/commands/pipeline.rs
@@ -92,86 +92,80 @@ impl Pipeline {
 
 		log::debug!("Expanding pipeline file into targets");
 		let base_path = PathBuf::from(path.parent().unwrap());
-		get_targets(base_path.clone(), &pipeline_data).for_each(
-			|(input_path, output_path, actions)| {
-				match make_paths(&output_path) {
+		get_targets(base_path, &pipeline_data).for_each(|(input_path, output_path, actions)| {
+			match make_paths(&output_path) {
+				Ok(_) => {}
+				Err(e) => {
+					log::error!("Failed to create target directory {}; {}", &output_path, e);
+					return;
+				}
+			}
+
+			if actions.is_empty() {
+				match std::fs::copy(&input_path, &output_path) {
 					Ok(_) => {}
 					Err(e) => {
-						log::error!("Failed to create target directory {}; {}", &output_path, e);
-						return;
+						log::error!("Failed to copy {} to {}; {}", input_path, output_path, e);
 					}
-				}
+				};
+				return;
+			}
 
-				if actions.is_empty() {
-					match std::fs::copy(&input_path, &output_path) {
-						Ok(_) => {}
-						Err(e) => {
-							log::error!("Failed to copy {} to {}; {}", input_path, output_path, e);
-						}
-					};
-					return;
-				}
+			let mut file = result!(load_image(&input_path, None));
 
-				let mut file = result!(load_image(&input_path, None));
-
-				log::debug!(
-					"Loaded {}, Executing {} actions",
-					&input_path,
-					actions.len()
-				);
-
-				let mut count = 1;
-				for step in actions {
-					match step {
-						Args::Rotate(rotate) => {
-							file = result!(rotate.run(&file));
-						}
-						Args::Extrude(extrude) => {
-							file = result!(extrude.run(&file));
-						}
-						Args::Scale(scale) => {
-							file = result!(scale.run(&file));
-						}
-						Args::Flip(flip) => {
-							file = result!(flip.run(&file));
-						}
-						Args::Remap(remap) => {
-							let palette = result!(load_image(&remap.palette, None));
-							let image_palette = result!(Palette::extract_from(&file));
-							let target_palette = result!(Palette::extract_from(&palette));
-
-							let mappings =
-								Palette::calculate_mapping(&image_palette, &target_palette);
-							file = result!(Remap::remap_image(file, mappings));
-						}
-						_ => {}
+			log::debug!(
+				"Loaded {}, Executing {} actions",
+				&input_path,
+				actions.len()
+			);
+
+			for step in actions {
+				match step {
+					Args::Rotate(rotate) => {
+						file = result!(rotate.run(&file));
+					}
+					Args::Extrude(extrude) => {
+						file = result!(extrude.run(&file));
 					}
+					Args::Scale(scale) => {
+						file = result!(scale.run(&file));
+					}
+					Args::Flip(flip) => {
+						file = result!(flip.run(&file));
+					}
+					Args::Remap(remap) => {
+						let palette = result!(load_image(&remap.palette, None));
+						let image_palette = result!(Palette::extract_from(&file));
+						let target_palette = result!(Palette::extract_from(&palette));
 
-					count += 1;
+						let mappings = Palette::calculate_mapping(&image_palette, &target_palette);
+						file = result!(Remap::remap_image(file, mappings));
+					}
+					_ => {}
 				}
+			}
 
-				let mut outer_target_path = PathBuf::from(&output_path);
-				outer_target_path.pop();
-
-				if let Err(e) = std::fs::create_dir(&outer_target_path) {
-					match e.kind() {
-						std::io::ErrorKind::AlreadyExists => { /* This is fine */ }
-						_ => log::error!(
-							"Failed to create containing directory {}; {}",
-							outer_target_path.to_string_lossy(),
-							e
-						),
-					}
+			let mut outer_target_path = PathBuf::from(&output_path);
+			outer_target_path.pop();
+
+			if let Err(e) = std::fs::create_dir(&outer_target_path) {
+				match e.kind() {
+					std::io::ErrorKind::AlreadyExists => { /* This is fine */ }
+					_ => log::error!(
+						"Failed to create containing directory {}; {}",
+						outer_target_path.to_string_lossy(),
+						e
+					),
 				}
+			}
 
-				match file.save(&output_path) {
-					Ok(_) => {}
-					Err(e) => {
-						log::error!("Failed to save to {}; {}", output_path, e);
-					}
+			match file.save(&output_path) {
+				Ok(_) => {}
+				Err(e) => {
+					log::error!("Failed to save to {}; {}", output_path, e);
 				}
-			},
-		);
+			}
+		});
 
 		Ok(())
 	}
@@ -211,7 +205,7 @@ fn get_targets(
 					(
 						join(&base_path, &input_path),
 						join(&base_path, &output_path),
-						(*value).actions.clone(),
+						value.actions.clone(),
 					)
 				})
 				.collect(),
@@ -223,7 +217,7 @@ fn get_targets(
 				.refs
 				.get(reference.as_str())
 				.iter()
-				.map(|value| (*value).actions.clone())
+				.map(|value| value.actions.clone())
 				.flat_map(|actions| {
 					let mut paths = Vec::new();
 					let target_path = join(&base_path, pattern);
diff --git a/src/commands/remap.rs b/src/commands/remap.rs
index 342999a..3dd3083 100644
--- a/src/commands/remap.rs
+++ b/src/commands/remap.rs
@@ -4,7 +4,7 @@ use image::{GenericImage, Pixel, Rgba};
 use num_traits::ToPrimitive;
 use serde::{Deserialize, Serialize};
 
-use crate::utils::{new_image, BasicRgba, OutputFormat, TypedOutputFormat};
+use crate::utils::{new_image, BasicRgba, OutputFormat};
 
 /// Convert the colour space of an image to that of a given palette file
 #[derive(Debug, Clone, Parser, Serialize, Deserialize)]
diff --git a/src/main.rs b/src/main.rs
index 84689c5..3338e4e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,10 +4,9 @@ mod format;
 mod utils;
 
 use clap::Parser;
-use image::{GenericImage, Rgba, SubImage};
 
 use crate::cli_args::Args;
-use crate::format::{load_image, Format};
+use crate::format::load_image;
 
 fn main() -> anyhow::Result<(), anyhow::Error> {
 	env_logger::Builder::from_env("LOG_LEVEL").init();
diff --git a/src/utils.rs b/src/utils.rs
index e5c952b..d29ee7c 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -5,7 +5,6 @@ use deltae::LabValue;
 use glam::Vec3;
 use image::{GenericImage, GenericImageView, Rgb, Rgba, RgbaImage, SubImage};
 use lab::Lab;
-use serde::{Deserialize, Serialize};
 
 #[derive(Clone, Copy)]
 pub struct SpriteData<'a, T: GenericImage> {
-- 
GitLab