1pub trait DisplayError {
2 fn format(&self, w: &mut dyn std::io::Write) -> std::io::Result<()>;
3
4 fn into_panic(&self) -> ! {
5 let mut message: Vec<u8> = "Error: ".into();
6 self.format(&mut message).unwrap();
7 panic!("{}", String::from_utf8_lossy(&message));
8 }
9}
10
11pub type Error = Box<dyn DisplayError>;
12pub type Result<T> = std::result::Result<T, Error>;
13
14impl<E: DisplayError + 'static> From<E> for Error {
15 fn from(e: E) -> Error {
16 Box::new(e)
17 }
18}
19
20pub trait DisplayErrorAuto {}
21
22impl<E: std::fmt::Display + DisplayErrorAuto> DisplayError for E {
23 fn format(&self, w: &mut dyn std::io::Write) -> std::io::Result<()> {
24 write!(w, "{}", self)
25 }
26}
27
28impl DisplayErrorAuto for xmltree::ParseError {}
29impl DisplayErrorAuto for xmltree::Error {}
30impl DisplayErrorAuto for std::io::Error {}
31impl DisplayErrorAuto for std::num::ParseIntError {}
32impl DisplayErrorAuto for std::num::TryFromIntError {}
33impl DisplayErrorAuto for svd_rs::SvdError {}
34impl DisplayErrorAuto for svd_encoder::EncodeError {}