use std::fmt;
#[derive(Debug, PartialEq)]
pub enum ValueErrorType {
InvalidTossi,
LimitLength,
}
impl fmt::Display for ValueErrorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ValueErrorType::InvalidTossi => write!(f, "101"),
ValueErrorType::LimitLength => write!(f, "102"),
}
}
}
#[derive(Debug, PartialEq)]
pub struct ValueError {
pub error: ValueErrorType,
pub description: String,
}
impl ValueError {
pub fn new(error: ValueErrorType) -> Self {
ValueError {
description: error.to_string(),
error,
}
}
}
impl fmt::Display for ValueError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.error)
}
}
#[derive(Debug, PartialEq)]
pub enum ParseErrorType {
InvalidValue(ValueErrorType),
AreNotBalanced,
IsNotBrace,
NestedParentheses,
SplitTossiWord,
TossiIsEmpty,
WordIsEmpty,
}
impl fmt::Display for ParseErrorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseErrorType::InvalidValue(_value_error) => write!(f, "201({_value_error})."),
ParseErrorType::AreNotBalanced => write!(f, "202"),
ParseErrorType::IsNotBrace => write!(f, "203"),
ParseErrorType::NestedParentheses => write!(f, "204"),
ParseErrorType::SplitTossiWord => write!(f, "205"),
ParseErrorType::TossiIsEmpty => write!(f, "206"),
ParseErrorType::WordIsEmpty => write!(f, "207"),
}
}
}
#[derive(Debug, PartialEq)]
pub struct ParseError {
pub error: ParseErrorType,
pub description: String,
}
impl ParseError {
pub fn new(error: ParseErrorType) -> Self {
ParseError {
description: error.to_string(),
error,
}
}
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.error)
}
}