doki_error/error/
error_std.rs

1use super::*;
2
3macro_rules! error_wrap {
4    ($t:ty => $name:ident) => {
5        impl From<$t> for DokiError {
6            fn from(e: $t) -> Self {
7                Self { kind: Box::new(DokiErrorKind::$name(e)), level: DiagnosticLevel::None, file: None, range: None }
8            }
9        }
10    };
11    ($($t:ty => $name:ident),+ $(,)?) => (
12        $(error_wrap!($t=>$name);)+
13    );
14}
15
16error_wrap![
17    std::io::Error  => IOError,
18    std::fmt::Error => FormatError,
19];
20
21impl From<Infallible> for DokiError {
22    fn from(_: Infallible) -> Self {
23        Self::unreachable()
24    }
25}
26
27impl From<()> for DokiError {
28    fn from(_: ()) -> Self {
29        Self::unreachable()
30    }
31}
32
33impl From<ParseError> for DokiError {
34    fn from(e: ParseError) -> Self {
35        Self::syntax_error(e.to_string())
36    }
37}