1pub type Result<T, E = DsntkError> = std::result::Result<T, E>;
5
6pub trait ToErrorMessage {
8 fn message(self) -> String;
10}
11
12#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct DsntkError(String);
15
16impl std::fmt::Display for DsntkError {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 write!(f, "{}", self.0)
20 }
21}
22
23impl DsntkError {
24 pub fn new(source: &str, message: &str) -> Self {
26 Self(format!("<{source}> {message}"))
27 }
28}
29
30impl<T> From<T> for DsntkError
31where
32 T: ToErrorMessage,
33{
34 fn from(value: T) -> Self {
36 let error_type_name = std::any::type_name::<T>().split("::").last().unwrap_or("UnknownError");
37 DsntkError::new(error_type_name, &value.message())
38 }
39}