use super::*;
#[must_use]
pub fn extract_panic_message(payload: &(dyn Any + Send)) -> String {
if let Some(static_message) = payload.downcast_ref::<&str>() {
return (*static_message).to_string();
}
if let Some(owned_message) = payload.downcast_ref::<String>() {
return owned_message.clone();
}
FAULT_UNKNOWN_PAYLOAD.to_string()
}
pub fn run_isolated<CallbackFn, ReturnValue>(operation: CallbackFn) -> Result<ReturnValue, String>
where
CallbackFn: FnOnce() -> ReturnValue,
{
match catch_unwind(AssertUnwindSafe(operation)) {
Ok(value) => Ok(value),
Err(payload) => Err(extract_panic_message(payload.as_ref())),
}
}