Skip to main content

Module unwind_protect

Module unwind_protect 

Source
Expand description

Safe API for Rโ€™s R_UnwindProtect

This module provides with_r_unwind_protect for handling R errors with Rust cleanup. It automatically runs Rust destructors when R errors occur.

Important: R uses longjmp for error handling, which normally bypasses Rust destructors. Use this API to ensure cleanup happens even when R errors occur.

Staticsยง

R_CONTINUATION_TOKEN ๐Ÿ”’
Global continuation token for R_UnwindProtect.

Functionsยง

get_continuation_token ๐Ÿ”’
Get or create the global continuation token.
panic_payload_to_r_error ๐Ÿ”’ โš 
Convert a Rust panic payload into an R error and continue unwinding on the R side.
panic_payload_to_string
Extract a message from a panic payload.
run_r_unwind_protect ๐Ÿ”’
Core R_UnwindProtect wrapper. Returns Ok(result) on success, Err(payload) on Rust panic, or diverges via R_ContinueUnwind on R longjmp.
with_r_unwind_protect
Execute a closure with R unwind protection.
with_r_unwind_protect_error_in_r
Like with_r_unwind_protect, but returns a tagged error SEXP on Rust panics instead of raising an R error via Rf_errorcall.
with_r_unwind_protect_sourced ๐Ÿ”’
Like with_r_unwind_protect, but reports panics with a custom [PanicSource].