|
@@ -1,5 +1,6 @@
|
|
use serde::Deserialize;
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
+use crate::errors::IncompleteMappingError;
|
|
use crate::image::{Image, Pixel};
|
|
use crate::image::{Image, Pixel};
|
|
use std::collections::{HashMap, HashSet};
|
|
use std::collections::{HashMap, HashSet};
|
|
|
|
|
|
@@ -12,28 +13,6 @@ struct ColorEntry {
|
|
#[derive(Deserialize, Debug)]
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct Mapping(HashMap<Pixel, String>);
|
|
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 {
|
|
impl Mapping {
|
|
pub fn load(
|
|
pub fn load(
|
|
path: impl AsRef<std::path::Path>,
|
|
path: impl AsRef<std::path::Path>,
|