Expand description
Worker thread infrastructure for safe Rust-R FFI.
§Public API
with_r_thread— Execute a closure on R’s main threadis_r_main_thread— Check if the current thread is R’s main thread
§Feature gate: worker-thread
Without the worker-thread cargo feature, all calls execute inline on
R’s main thread:
with_r_thread(f)runsf()directly (panics if not on main thread)run_on_worker(f)runsf()directly, returnsOk(f())
With the feature enabled, a dedicated worker thread is spawned at init time.
with_r_thread routes calls from the worker back to main, and run_on_worker
dispatches closures to the worker with bidirectional communication.
§Initialization
miniextendr_runtime_init must be called from R’s main thread before any
R FFI APIs. Typically done in R_init_<pkgname>().
Structs§
- Sendable 👻
- Wrapper to mark values as Send for main-thread routing.
Statics§
Functions§
- assert_
runtime_ 🔒initialized - Panic if the runtime hasn’t been initialized.
- has_
worker_ 🔒context - Check whether the current thread has a worker routing context.
- is_
r_ main_ thread - Check if the current thread is R’s main thread.
- miniextendr_
runtime_ 👻init - Initialize the miniextendr runtime.
- miniextendr_
runtime_ 👻shutdown - Shut down the miniextendr worker thread synchronously.
- panic_
message_ 👻to_ r_ error - Raise an R error from a panic message. Does not return.
- run_
on_ 👻worker - Run a closure on the worker thread with proper cleanup on panic.
- with_
r_ thread - Execute a closure on R’s main thread, returning the result.