Skip to main content

with_r_unwind_protect

Function with_r_unwind_protect 

Source
pub fn with_r_unwind_protect<F>(f: F, call: Option<SEXP>) -> SEXP
where F: FnOnce() -> SEXP,
Expand description

Run a closure under R_UnwindProtect, returning a tagged condition SEXP on Rust panics instead of raising an R error.

This is the transport for all #[miniextendr] functions and methods. The returned error/condition SEXP is inspected by the generated R wrapper which raises a proper R condition past the Rust boundary, with rust_* class layering.

Recognises crate::condition::RCondition payloads (from error!(), warning!(), message!(), condition!()) before falling through to the generic panic→string path.

R-origin errors (longjmp) still pass through via R_ContinueUnwind.

For guard sites that have no R wrapper to inspect a tagged SEXP (ALTREP RUnwind callbacks, FFI guard tests) see with_r_unwind_protect_or_raise; for trait-ABI vtable shims see with_r_unwind_protect_shim.