1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/// Format an error and its full cause chain into a [`Formatter`](std::fmt::Formatter).
///
/// Useful for implementing [`std::fmt::Display`] on custom error types that wrap
/// other errors — each cause is printed on its own line with a `"Caused by:"` prefix.
///
/// # Examples
///
/// ```
/// use mae::util::error_chain_fmt;
/// use std::fmt;
///
/// #[derive(Debug)]
/// struct Inner;
/// impl fmt::Display for Inner {
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "inner") }
/// }
/// impl std::error::Error for Inner {}
///
/// #[derive(Debug)]
/// struct Outer(Inner);
/// impl fmt::Display for Outer {
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// error_chain_fmt(&self.0, f)
/// }
/// }
/// impl std::error::Error for Outer {
/// fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
/// }
///
/// let err = Outer(Inner);
/// let s = format!("{}", err);
/// assert!(s.contains("inner"));
/// ```