pub fn guarded_ffi_call<F, R>(f: F, mode: GuardMode, source: PanicSource) -> Rwhere
F: FnOnce() -> R,Expand description
Execute f inside an FFI guard selected by mode.
On panic:
- Extracts the panic message from the payload.
- Fires
crate::panic_telemetrywithsource. - For
GuardMode::CatchUnwind: raises R error viaRf_error(diverges — never returns). - For
GuardMode::RUnwind: delegates towith_r_unwind_protect_sourced.
Deferred conditions signal on R’s main thread before return (or panic
conversion). Use this boundary on the main thread. Any SEXP held in the
generic result must be rooted, e.g. by returning OwnedProtect.
§Parameters
f: The closure to execute.mode: Which guard strategy to use.source: Attribution for telemetry if a panic occurs.
§Note on fallback
GuardMode::CatchUnwind diverges on panic (Rf_error never returns), so no
fallback value is needed. If you need a fallback (e.g. connection trampolines
that must return a value on panic without calling R), use
guarded_ffi_call_with_fallback instead.