ipc_communication/
panic_error.rs1use std::{any::Any, error::Error, fmt};
2
3pub struct PanicError {
5 inner: Box<dyn Any + Send + 'static>,
6}
7
8impl fmt::Display for PanicError {
9 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10 fmt::Display::fmt(self.as_str(), f)
11 }
12}
13
14impl fmt::Debug for PanicError {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 fmt::Debug::fmt(self.as_str(), f)
17 }
18}
19
20impl PanicError {
21 pub(crate) fn new(inner: Box<dyn Any + Send + 'static>) -> Self {
22 PanicError { inner }
23 }
24
25 fn as_str(&self) -> &str {
26 self.inner
27 .downcast_ref::<String>()
28 .map(String::as_str)
29 .or_else(|| self.inner.downcast_ref::<&'static str>().copied())
30 .unwrap_or("Box<dyn Any>")
31 }
32}
33
34impl Error for PanicError {}