Ver código fonte

split out errors

Getty Ritter 10 meses atrás
pai
commit
f5e2f6878e
3 arquivos alterados com 25 adições e 22 exclusões
  1. 1 22
      src/data.rs
  2. 23 0
      src/errors.rs
  3. 1 0
      src/lib.rs

+ 1 - 22
src/data.rs

@@ -1,5 +1,6 @@
 use serde::Deserialize;
 
+use crate::errors::IncompleteMappingError;
 use crate::image::{Image, Pixel};
 use std::collections::{HashMap, HashSet};
 
@@ -12,28 +13,6 @@ struct ColorEntry {
 #[derive(Deserialize, Debug)]
 pub struct Mapping(HashMap<Pixel, String>);
 
-#[derive(Debug)]
-pub struct IncompleteMappingError {
-    path: std::path::PathBuf,
-    missing_colors: Vec<Pixel>,
-}
-
-impl std::fmt::Display for IncompleteMappingError {
-    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        writeln!(
-            f,
-            "`{:?}` is missing entries for the following pixel colors:",
-            self.path
-        )?;
-        for color in self.missing_colors.iter() {
-            writeln!(f, "  - {:?}", color)?;
-        }
-        Ok(())
-    }
-}
-
-impl std::error::Error for IncompleteMappingError {}
-
 impl Mapping {
     pub fn load(
         path: impl AsRef<std::path::Path>,

+ 23 - 0
src/errors.rs

@@ -0,0 +1,23 @@
+use crate::image::Pixel;
+
+#[derive(Debug)]
+pub struct IncompleteMappingError {
+    pub path: std::path::PathBuf,
+    pub missing_colors: Vec<Pixel>,
+}
+
+impl std::fmt::Display for IncompleteMappingError {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        writeln!(
+            f,
+            "`{:?}` is missing entries for the following pixel colors:",
+            self.path
+        )?;
+        for color in self.missing_colors.iter() {
+            writeln!(f, "  - {:?}", color)?;
+        }
+        Ok(())
+    }
+}
+
+impl std::error::Error for IncompleteMappingError {}

+ 1 - 0
src/lib.rs

@@ -1,3 +1,4 @@
 pub mod data;
 pub mod draw;
+pub mod errors;
 pub mod image;