zng_task/crate_util.rs
1/// Converts a [`std::panic::catch_unwind`] payload to a str.
2pub fn panic_str<'s>(payload: &'s Box<dyn std::any::Any + Send + 'static>) -> &'s str {
3 if let Some(s) = payload.downcast_ref::<&str>() {
4 s
5 } else if let Some(s) = payload.downcast_ref::<String>() {
6 s
7 } else {
8 "<unknown-panic-message-type>"
9 }
10}
11
12/// The result that is returned by [`std::panic::catch_unwind`].
13pub type PanicResult<R> = std::thread::Result<R>;