refactor: refactor

This commit is contained in:
graelo 2020-05-25 23:06:00 +02:00
parent 37f22b67af
commit 905bd2862c
7 changed files with 1200 additions and 884 deletions

View file

@ -2,17 +2,45 @@ use std::fmt;
#[derive(Debug)]
pub enum ParseError {
ExpectedSurroundingPair,
UnknownAlphabet,
UnknownColor,
ExpectedSurroundingPair,
UnknownAlphabet,
UnknownColor,
ExpectedPaneIdMarker,
ExpectedInt(std::num::ParseIntError),
ExpectedBool(std::str::ParseBoolError),
ProcessFailure(String),
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseError::ExpectedSurroundingPair => write!(f, "Expected 2 chars"),
ParseError::UnknownAlphabet => write!(f, "Expected a known alphabet"),
ParseError::UnknownColor => write!(f, "Expected ANSI color name (magenta, cyan, black, ...)"),
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseError::ExpectedSurroundingPair => write!(f, "Expected 2 chars"),
ParseError::UnknownAlphabet => write!(f, "Expected a known alphabet"),
ParseError::UnknownColor => {
write!(f, "Expected ANSI color name (magenta, cyan, black, ...)")
}
ParseError::ExpectedPaneIdMarker => write!(f, "Expected pane id marker"),
ParseError::ExpectedInt(msg) => write!(f, "Expected an int: {}", msg),
ParseError::ExpectedBool(msg) => write!(f, "Expected a bool: {}", msg),
ParseError::ProcessFailure(msg) => write!(f, "{}", msg),
}
}
}
impl From<std::num::ParseIntError> for ParseError {
fn from(error: std::num::ParseIntError) -> Self {
ParseError::ExpectedInt(error)
}
}
impl From<std::str::ParseBoolError> for ParseError {
fn from(error: std::str::ParseBoolError) -> Self {
ParseError::ExpectedBool(error)
}
}
impl From<std::io::Error> for ParseError {
fn from(error: std::io::Error) -> Self {
ParseError::ProcessFailure(error.to_string())
}
}
}