From f08a4c66a1d8474be4b50b490258943d0048d5bb Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 26 Jan 2024 12:58:51 -0800 Subject: [PATCH] [core] Use TryFromCharError in TryFrom for Color --- core/src/colors.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/core/src/colors.rs b/core/src/colors.rs index dd0bf12..4e94fed 100644 --- a/core/src/colors.rs +++ b/core/src/colors.rs @@ -1,14 +1,8 @@ // Eryn Wells -use crate::try_from_string; +use crate::{errors::TryFromCharError, try_from_string}; use std::fmt; -#[derive(Debug, Eq, PartialEq)] -pub enum TryFromError { - InvalidCharacter, - ZeroLengthString, -} - #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub enum Color { White = 0, @@ -48,13 +42,13 @@ impl fmt::Display for Color { } impl TryFrom for Color { - type Error = TryFromError; + type Error = TryFromCharError; fn try_from(value: char) -> Result { match value { 'w' | 'W' => Ok(Color::White), 'b' | 'B' => Ok(Color::Black), - _ => Err(TryFromError::InvalidCharacter), + _ => Err(TryFromCharError), } } }