1use std::{any, convert::Infallible, error::Error};
2
3use crate::{Backtrace, Location};
4
5pub trait Error2: Error {
6 fn backtrace(&self) -> &Backtrace;
7
8 fn backtrace_mut(&mut self) -> &mut Backtrace;
9
10 #[doc(hidden)]
11 fn push_error(&mut self, location: Location) {
12 let type_name = any::type_name::<Self>();
13 let display = self.to_string();
14
15 self.backtrace_mut()
16 .push_error(type_name, display, location);
17 }
18}
19
20impl Error2 for Infallible {
21 fn backtrace(&self) -> &Backtrace {
22 match *self {}
23 }
24
25 fn backtrace_mut(&mut self) -> &mut Backtrace {
26 match *self {}
27 }
28}
29
30impl<T: Error2> Error2 for Box<T> {
31 #[inline]
32 fn backtrace(&self) -> &Backtrace {
33 self.as_ref().backtrace()
34 }
35
36 #[inline]
37 fn backtrace_mut(&mut self) -> &mut Backtrace {
38 self.as_mut().backtrace_mut()
39 }
40}