use std::any::Any; use std::fmt; /// Error type returned when a panic occurs during execution. pub struct ProgramPanic { pub payload: Box, } impl fmt::Display for ProgramPanic { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(s) = self.payload.downcast_ref::<&str>() { write!(f, "{s}") } else if let Some(s) = self.payload.downcast_ref::() { write!(f, "{s}") } else { write!(f, "") } } } impl ProgramPanic { #[must_use] pub fn new(payload: Box) -> Self { ProgramPanic { payload } } } impl fmt::Debug for ProgramPanic { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self.payload) } }