diff options
| author | troido <troido@protonmail.com> | 2020-04-06 10:37:53 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-06 10:37:53 +0200 |
| commit | e8d3e3c4f69fc5bab2b32b16b7c8c2c4a8a89a4b (patch) | |
| tree | 67986bb0c0af1abe61dc9846d1a6c8c9b8e2c4b0 /src/errors.rs | |
| parent | ff457701ff56072914acb8a7160cd02c2a07095a (diff) | |
made parseerrors their own thing
Diffstat (limited to 'src/errors.rs')
| -rw-r--r-- | src/errors.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000..294159c --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,47 @@ + +use std::error::Error; +use std::fmt::{Display, Formatter}; + +pub type AnyError = Box<dyn Error + 'static>; +pub type Result<T> = std::result::Result<T, AnyError>; + +#[derive(Debug)] +pub struct AError { + pub text: 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:tt)*) => {Box::new(crate::errors::AError{text: format!($($description)*)})} +} + + + +#[derive(Debug)] +pub struct ParseError { + pub text: String +} +impl Error for ParseError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + None + } +} +impl Display for ParseError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "Error: {}", self.text) + } +} +#[macro_export] +macro_rules! perr { + ($($description:tt)*) => {crate::errors::ParseError{text: format!($($description)*)}} +} +pub type PResult<T> = std::result::Result<T, ParseError>; |
