pub fn guard<T>(what: &str, f: impl FnOnce() -> T) -> KitResult<T>Expand description
Wraps one cross-boundary call in catch_unwind.
what is only used in the error message, e.g. "entry()" / "command()".
ยงExample
use crate_plugin_kit::panic::guard;
// Pretend this reads an exported symbol from a plugin and then calls it
fn call_plugin(entry: *const (), arg: u32) -> u32 {
guard("command()", || unsafe { read_field(entry) + arg }).unwrap_or(0)
}
/// # Safety
/// The caller guarantees that `entry` points at a struct with a matching layout.
unsafe fn read_field(_entry: *const ()) -> u32 { 1 }