1use std::fmt::{Display, Formatter};
6
7#[derive(Debug, Clone)]
8pub struct Error {
9 msg: String,
10}
11
12impl Display for Error {
13 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
14 write!(f, "Error: {}", self.msg)
15 }
16}
17
18impl std::error::Error for Error {}
19
20macro_rules! impl_error {
21 ($msg:literal, $($typ:ty)+) => {
22 impl From<$($typ)+> for Error {
23 fn from(value: $($typ)+) -> Error {
24 Error {
25 msg: format!("{value}")
26 }
27 }
28 }
29 };
30}
31
32impl_error!("IOError", std::io::Error);
33impl_error!("Git", std::path::StripPrefixError);
34#[cfg(feature = "git")]
35impl_error!("Git", git2::Error);
36#[cfg(feature = "git")]
37impl_error!("Git", irox_git_tools::Error);