use std::error::Error as StdError;
use std::fmt;
#[macro_export]
macro_rules! error
{
( $err_type:ident, $msg:literal ) =>
{
{
Error::$err_type(String::from($msg))
}
};
( $err_type:ident, $msg:literal $(, $x:expr)+) =>
{
{
Error::$err_type(format!($msg $(, $x)+))
}
};
}
#[macro_export]
macro_rules! rterr
{
($msg:literal $(, $x:expr)*) =>
{
error!(RuntimeError, $msg $(, $x)*)
};
}
#[macro_export]
macro_rules! xmlerr
{
($msg:literal $(, $x:expr)*) =>
{
error!(XMLError, $msg $(, $x)*)
};
}
#[derive(Debug, Clone)]
pub enum Error
{
RuntimeError(String),
XMLError(String),
}
impl fmt::Display for Error
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
match self
{
Error::RuntimeError(msg) => write!(f, "Runtime error: {}", msg),
Error::XMLError(msg) => write!(f, "XML error: {}", msg),
}
}
}
impl StdError for Error
{
fn source(&self) -> Option<&(dyn StdError + 'static)> {None}
}