kodept_macros/error/
mod.rs

1use std::error::Error;
2use derive_more::{Display};
3
4pub mod compiler_crash;
5pub mod report;
6pub mod report_collector;
7pub mod traits;
8
9#[derive(Debug, Display, Default)]
10#[display(fmt = "Compilation failed due to produced errors")]
11pub struct ErrorReported {
12    cause: Option<Box<dyn Error + Send + Sync + 'static>>
13}
14
15impl ErrorReported {
16    pub fn with_cause<E: Error + Send + Sync + 'static>(error: E) -> Self {
17        Self {
18            cause: Some(Box::new(error)),
19        }
20    }
21    
22    pub fn new() -> Self {
23        Self::default()
24    }
25}
26
27impl Error for ErrorReported {
28    fn source(&self) -> Option<&(dyn Error + 'static)> {
29        match &self.cause {
30            None => None,
31            Some(x) => Some(x.as_ref()),
32        }
33    }
34}