Skip to main content

with_r_unwind_protect

Function with_r_unwind_protect 

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

Execute a closure with R unwind protection.

If the closure panics, the panic is caught and converted to an R error. If R raises an error (longjmp), all Rust RAII resources are properly dropped before R continues unwinding.

§Arguments

  • f - The closure to execute
  • call - Optional R call SEXP for better error messages

§Example

let result: i32 = with_r_unwind_protect(|| {
    // Code that might call R APIs that can error
    42
}, None);