eastwind_blogger/utils/
error.rs1use std::error::Error;
2use std::fmt;
3
4#[derive(Debug)]
5pub struct ParserError {
6 details: String,
7}
8
9#[derive(Debug)]
10pub struct RendererError {
11 details: String,
12}
13
14#[derive(Debug)]
15pub struct FsError {
16 details: String,
17}
18
19macro_rules! impl_error {
20 ($ty:ty) => {
21 impl $ty {
22 pub fn new(msg: &str) -> Self {
23 Self {
24 details: msg.to_string(),
25 }
26 }
27 }
28
29 impl fmt::Display for $ty {
30 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31 write!(f, "{}", self.details)
32 }
33 }
34
35 impl Error for $ty {
36 fn description(&self) -> &str {
37 &self.details
38 }
39 }
40 };
41}
42
43impl_error!(ParserError);
44impl_error!(RendererError);
45impl_error!(FsError);