1use std::fmt;
2use std::hash::Hash;
3
4#[derive(PartialEq)]
6pub enum Error {
7 Generic(String),
8 Pest(String),
9}
10
11pub type Result<T> = std::result::Result<T, Error>;
12
13impl fmt::Display for Error {
14 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15 match self {
16 Self::Generic(message) => write!(f, "{}", message),
17 Self::Pest(message) => write!(f, "{}", message),
18 }
19 }
20}
21
22impl fmt::Debug for Error {
23 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24 write!(f, "{}, {{ file: {}, line: {} }}", self, file!(), line!())
25 }
26}
27
28impl<R> From<pest::error::Error<R>> for Error
29where
30 R: Ord + Copy + fmt::Debug + Hash,
31{
32 fn from(pest_error: pest::error::Error<R>) -> Self {
33 Self::Pest(pest_error.to_string())
34 }
35}
36
37#[macro_export]
38macro_rules! error {
39 ($($arg:tt)*) => {{
40 let res = Error::Generic(format!($($arg)*));
41 res
42 }}
43}