euv-core 0.52.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Extracts a human-readable message from an arbitrary Rust panic payload.
///
/// # Arguments
///
/// - `&(dyn Any + Send)` - Borrowed panic payload captured by `catch_unwind`.
///
/// # Returns
///
/// - `String` - Extracted panic string or a deterministic fallback message.
#[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()
}

/// Runs `operation` inside `catch_unwind` and converts any panic payload into an extracted error string.
///
/// # Arguments
///
/// - `CallbackFn` - Closure executed inside panic isolation.
///
/// # Returns
///
/// - `Result<ReturnValue, String>` - `Ok(value)` on normal completion or `Err(message)` if `operation` panicked.
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())),
    }
}