blob: a6874cf864e3e7ec8fd75e30b2251820f4726d1c (
plain) (
blame)
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
|
use std::any::Any;
use std::fmt;
use thiserror::Error;
/// Error type returned when a panic occurs during execution.
#[derive(Error)]
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 }
}
}
impl fmt::Debug for ProgramPanic {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.payload)
}
}
|