diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-05-15 23:03:07 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-15 23:03:07 +0800 |
| commit | de448a04dc594f0938210abaa12de0e168f5741a (patch) | |
| tree | ba1e6e91ad495779c647a5bca83eada3b5c9d837 | |
| parent | 31638f3cf6cf8266edc0c8b30f44407229f79637 (diff) | |
Replace derive-macro Display impl with manual formatting
| -rw-r--r-- | mingling_core/src/program/error.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/mingling_core/src/program/error.rs b/mingling_core/src/program/error.rs index 5e92a42..a6874cf 100644 --- a/mingling_core/src/program/error.rs +++ b/mingling_core/src/program/error.rs @@ -4,11 +4,22 @@ use thiserror::Error; /// Error type returned when a panic occurs during execution. #[derive(Error)] -#[error("execution panicked: {payload:?}")] pub struct ProgramPanic { pub payload: Box<dyn Any + Send>, } +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::<String>() { + write!(f, "{}", s) + } else { + write!(f, "") + } + } +} + impl ProgramPanic { pub fn new(payload: Box<dyn Any + Send>) -> Self { ProgramPanic { payload } |
