1use std::error::Error as StdError;
2use std::fmt;
3
4#[macro_export]
5macro_rules! error
6{
7 ( $err_type:ident, $msg:literal ) =>
8 {
9 {
10 Error::$err_type(String::from($msg))
11 }
12 };
13 ( $err_type:ident, $msg:literal $(, $x:expr)+) =>
14 {
15 {
16 Error::$err_type(format!($msg $(, $x)+))
17 }
18 };
19}
20
21#[macro_export]
23macro_rules! rterr
24{
25 ($msg:literal $(, $x:expr)*) =>
26 {
27 error!(RuntimeError, $msg $(, $x)*)
28 };
29}
30
31#[macro_export]
33macro_rules! xmlerr
34{
35 ($msg:literal $(, $x:expr)*) =>
36 {
37 error!(XMLError, $msg $(, $x)*)
38 };
39}
40
41#[derive(Debug, Clone)]
42pub enum Error
43{
44 RuntimeError(String),
50 XMLError(String),
51}
52
53impl fmt::Display for Error
54{
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
56 {
57 match self
58 {
59 Error::RuntimeError(msg) => write!(f, "Runtime error: {}", msg),
60 Error::XMLError(msg) => write!(f, "XML error: {}", msg),
61 }
62 }
63}
64
65impl StdError for Error
66{
67 fn source(&self) -> Option<&(dyn StdError + 'static)> {None}
68}