sc_scraping/
error.rs

1use std::{borrow::Cow, error::Error, fmt::Display};
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Serialize, Deserialize)]
6pub enum ScScrapingError<'a> {
7    Citizen { message: Cow<'a, str> },
8    Organization { message: Cow<'a, str> },
9}
10
11impl<'a> ScScrapingError<'a> {
12    pub fn citizen<S>(message: S) -> Self
13    where
14        S: Into<Cow<'a, str>>,
15    {
16        Self::Citizen {
17            message: message.into(),
18        }
19    }
20
21    pub fn organization<S>(message: S) -> Self
22    where
23        S: Into<Cow<'a, str>>,
24    {
25        Self::Organization {
26            message: message.into(),
27        }
28    }
29}
30
31impl<'a> Error for ScScrapingError<'a> {}
32impl<'a> Display for ScScrapingError<'a> {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34        match self {
35            Self::Citizen { message } => write!(f, "{message}"),
36            Self::Organization { message } => write!(f, "{message}"),
37        }
38    }
39}