1pub use std::error::Error;
10pub use thiserror::Error;
11
12use crate::prelude::*;
13
14#[derive(Error, From)]
16pub struct Panic {
17 pub value: Box<dyn Any + Send>,
19}
20
21impl Panic {
22 pub fn value_str(&self) -> Option<&str> {
24 if let Some(string) = self.value.downcast_ref::<String>() {
25 Some(string)
26 } else if let Some(string) = self.value.downcast_ref::<&'static str>() {
27 Some(string)
28 } else {
29 None
30 }
31 }
32}
33
34impl Debug for Panic {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 write!(f, "PanicError")?;
37
38 if let Some(value) = self.value_str() {
39 write!(f, "({:?})", value)?;
40 }
41
42 Ok(())
43 }
44}
45
46impl Display for Panic {
47 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48 write!(f, "Panicked")?;
49
50 if let Some(value) = self.value_str() {
51 write!(f, " with `{}`", value)?;
52 }
53
54 write!(f, ".")
55 }
56}