Skip to main content

catch_panic

Function catch_panic 

Source
pub fn catch_panic<F>(f: F) -> FfiResult
Expand description

Run f and convert any Rust panic into an FfiResult error.

This is the critical safety wrapper used by every extern "C" function in this crate. A panic unwind crossing the FFI boundary is undefined behaviour; catch_panic ensures it never happens.

§Example

#[no_mangle]
pub extern "C" fn my_ffi_fn(buf: FfiBuffer) -> FfiResult {
    catch_panic(|| {
        // ... do work, return Result<FfiBuffer, FfiError>
        Ok(buf)
    })
}