[core] Use TryFromCharError in TryFrom<char> for Color
This commit is contained in:
parent
54c94a93aa
commit
f08a4c66a1
1 changed files with 3 additions and 9 deletions
|
@ -1,14 +1,8 @@
|
||||||
// Eryn Wells <eryn@erynwells.me>
|
// Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
use crate::try_from_string;
|
use crate::{errors::TryFromCharError, try_from_string};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
|
||||||
pub enum TryFromError {
|
|
||||||
InvalidCharacter,
|
|
||||||
ZeroLengthString,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
pub enum Color {
|
pub enum Color {
|
||||||
White = 0,
|
White = 0,
|
||||||
|
@ -48,13 +42,13 @@ impl fmt::Display for Color {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<char> for Color {
|
impl TryFrom<char> for Color {
|
||||||
type Error = TryFromError;
|
type Error = TryFromCharError;
|
||||||
|
|
||||||
fn try_from(value: char) -> Result<Self, Self::Error> {
|
fn try_from(value: char) -> Result<Self, Self::Error> {
|
||||||
match value {
|
match value {
|
||||||
'w' | 'W' => Ok(Color::White),
|
'w' | 'W' => Ok(Color::White),
|
||||||
'b' | 'B' => Ok(Color::Black),
|
'b' | 'B' => Ok(Color::Black),
|
||||||
_ => Err(TryFromError::InvalidCharacter),
|
_ => Err(TryFromCharError),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue