Getty Ritter 3 months ago
parent
commit
21113edc58
2 changed files with 16 additions and 19 deletions
  1. 2 2
      src/data.rs
  2. 14 17
      src/file.rs

+ 2 - 2
src/data.rs

@@ -28,7 +28,7 @@ impl ColorEntry {
             }
             _ => panic!("Missing `color` in entry"),
         };
-        if let Some(_) = entry.get("blank") {
+        if entry.get("blank").is_some() {
             return Ok((color, None));
         }
         let name = entry["name"].as_str().unwrap().to_owned();
@@ -66,7 +66,7 @@ impl Mapping {
             .collect::<HashSet<Pixel>>();
         let missing_colors = all_image_colors
             .into_iter()
-            .filter(|c| !color_map.contains_key(&c))
+            .filter(|c| !color_map.contains_key(c))
             .collect::<Vec<Pixel>>();
         if !missing_colors.is_empty() {
             return Err(Box::new(IncompleteMappingError {

+ 14 - 17
src/file.rs

@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
 use std::collections::HashMap;
 use std::io::{Read, Seek, Write};
 
-const CURRENT_VERSION: &'static str = "0";
+const CURRENT_VERSION: &str = "0";
 
 #[derive(Debug, Clone, Copy)]
 pub enum StitchType {
@@ -16,11 +16,11 @@ pub enum StitchType {
 }
 
 impl StitchType {
-    fn to_u8(&self) -> u8 {
+    fn to_u8(self) -> u8 {
         match self {
-            StitchType::Normal => 'x' as u8,
-            StitchType::HalfUp => '/' as u8,
-            StitchType::HalfDown => '\\' as u8,
+            StitchType::Normal => b'x',
+            StitchType::HalfUp => b'/',
+            StitchType::HalfDown => b'\\',
         }
     }
 }
@@ -76,14 +76,10 @@ impl ThymeFile {
         let payload = image
             .iter()
             .map(|(_idx, pixel)| {
-                if let Some(color) = lookup.get(&pixel) {
-                    Some(Stitch {
-                        color: *color,
-                        typ: StitchType::Normal,
-                    })
-                } else {
-                    None
-                }
+                lookup.get(&pixel).map(|color| Stitch {
+                    color: *color,
+                    typ: StitchType::Normal,
+                })
             })
             .collect();
 
@@ -209,14 +205,15 @@ impl ThymeFile {
     fn json_stitches(&self) -> Vec<Option<IntermediateStitch>> {
         self.payload
             .iter()
-            .map(|stitch| match stitch {
-                Some(s) => Some(IntermediateStitch(s.typ.to_u8(), s.color.idx)),
-                None => None,
+            .map(|stitch| {
+                stitch
+                    .as_ref()
+                    .map(|s| IntermediateStitch(s.typ.to_u8(), s.color.idx))
             })
             .collect()
     }
 
-    pub fn iter<'a>(&'a self) -> ThymeImageIterator<'a> {
+    pub fn iter(&self) -> ThymeImageIterator<'_> {
         ThymeImageIterator {
             palette: &self.palette,
             x: 0,