1 #![allow(missing_docs)]
2 
3 use core::fmt::{Debug, Display};
4 
5 pub trait Error: Debug + Display {
description(&self) -> &str6     fn description(&self) -> &str {
7         "description() is deprecated; use Display"
8     }
cause(&self) -> Option<&dyn Error>9     fn cause(&self) -> Option<&dyn Error> {
10         self.source()
11     }
source(&self) -> Option<&(dyn Error + 'static)>12     fn source(&self) -> Option<&(dyn Error + 'static)> {
13         None
14     }
15 }
16 
17 macro_rules! impl_error {
18     ($($e:path),*) => {
19         $(
20             impl Error for $e {}
21         )*
22     }
23 }
24 
25 // All errors supported by our minimum suported Rust version can be supported by
26 // default.
27 impl_error![
28     core::str::ParseBoolError,    // 1.0
29     core::str::Utf8Error,         // 1.0
30     core::num::ParseIntError,     // 1.0
31     core::num::ParseFloatError,   // 1.0
32     core::char::DecodeUtf16Error, // 1.9
33     core::fmt::Error,             // 1.11
34     core::cell::BorrowMutError,   // 1.13
35     core::cell::BorrowError,      // 1.13
36     core::char::ParseCharError    // 1.20
37 ];
38 
39 // We can gate these together with std futures.
40 #[cfg(feature = "futures")]
41 impl_error![
42     core::num::TryFromIntError,     // 1.34
43     core::array::TryFromSliceError, // 1.34
44     core::char::CharTryFromError    // 1.34
45 ];
46