| 1 |
use crate::write_location; |
| 2 |
use std::fmt::{Debug, Display, Formatter}; |
| 3 |
use std::panic::Location; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
pub struct ChainedError { |
| 11 |
pub(crate) err: Box<dyn std::error::Error + Send + Sync + 'static>, |
| 12 |
pub(crate) location: &'static Location<'static>, |
| 13 |
pub(crate) source: Option<Box<ChainedError>>, |
| 14 |
} |
| 15 |
|
| 16 |
impl Debug for ChainedError { |
| 17 |
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 18 |
Debug::fmt(&self.err, f) |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
impl Display for ChainedError { |
| 23 |
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 24 |
Display::fmt(&self.err, f)?; |
| 25 |
if !f.alternate() { |
| 26 |
write_location(f, self.location)?; |
| 27 |
} |
| 28 |
Ok(()) |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
impl std::error::Error for ChainedError { |
| 33 |
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 34 |
self.source.as_ref().map(|e| e as &(dyn std::error::Error + 'static)) |
| 35 |
} |
| 36 |
} |