use std::{error::Error, fmt::Display};
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ParseErrorKind {
UnexpectedEof,
InvalidCharacter,
}
#[derive(Debug, PartialEq)]
pub struct ParseError {
pub kind: ParseErrorKind,
}
impl Display for ParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.kind {
ParseErrorKind::UnexpectedEof => write!(f, "unexpected eof"),
ParseErrorKind::InvalidCharacter => write!(f, "invalid character"),
}
}
}
impl Error for ParseError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
fn cause(&self) -> Option<&dyn Error> {
self.source()
}
}