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#[derive(Debug, Clone)]
32pub enum Error
33{
34 RuntimeError(String),
40 FormatError(String),
41}
42
43impl fmt::Display for Error
44{
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
46 {
47 match self
48 {
49 Error::RuntimeError(msg) => write!(f, "Runtime error: {}", msg),
50 Error::FormatError(msg) => write!(f, "Format error: {}", msg),
51 }
52 }
53}
54
55impl StdError for Error
56{
57 fn source(&self) -> Option<&(dyn StdError + 'static)> {None}
58}