summaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/util.rs b/src/util.rs
index 34d5670..1aee8a4 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,5 +1,6 @@
-
+use std::error::Error;
+use std::fmt::{Display, Formatter};
use std::cmp::{min, max};
use serde_json::Value;
@@ -12,6 +13,46 @@ pub trait ToJson {
}
+pub type AnyError = Box<dyn Error + 'static>;
+pub type Result<T> = std::result::Result<T, AnyError>;
+
+#[derive(Debug)]
+pub struct AError {
+ text: String
+}
+
+impl AError {
+ pub fn new(txt: &str) -> Self{
+ AError {
+ text: txt.to_string()
+ }
+ }
+}
+
+impl Error for AError {
+ fn source(&self) -> Option<&(dyn Error + 'static)> {
+ None
+ }
+}
+
+impl Display for AError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ write!(f, "Error: {}", self.text)
+ }
+}
+
+
+#[macro_export]
+macro_rules! aerr {
+ ($description:expr) => {Box::new(crate::util::AError::new($description))}
+}
+
+#[macro_export]
+macro_rules! err {
+ ($description:expr) => {Err(crate::aerr!($description))}
+}
+
+
#[macro_export]
macro_rules! hashmap {
( $($key:expr => $value:expr ),* ) => {{