pub struct WorkerUnprotectGuard(i32);Expand description
A Send-safe guard that calls Rf_unprotect(n) on drop via with_r_thread.
Use this when you Rf_protect on the R main thread, then need the unprotect
to happen when a guard drops on a worker thread (e.g., rayon parallel code).
OwnedProtect and ProtectScope are !Send — they can only be used on
the R main thread. WorkerUnprotectGuard fills the gap for cross-thread patterns
where allocation + protect happen on the R thread but the guard lives on a worker.
§Example
ⓘ
use miniextendr_api::gc_protect::WorkerUnprotectGuard;
let sexp = with_r_thread(|| unsafe {
let sexp = Rf_allocVector(REALSXP, n);
Rf_protect(sexp);
sexp
});
let _guard = WorkerUnprotectGuard::new(1);
// ... parallel work on sexp's data ...
// _guard drops here, dispatching Rf_unprotect(1) back to R threadTuple Fields§
§0: i32Implementations§
Trait Implementations§
Source§impl Drop for WorkerUnprotectGuard
impl Drop for WorkerUnprotectGuard
impl Send for WorkerUnprotectGuard
Auto Trait Implementations§
impl Freeze for WorkerUnprotectGuard
impl RefUnwindSafe for WorkerUnprotectGuard
impl Sync for WorkerUnprotectGuard
impl Unpin for WorkerUnprotectGuard
impl UnsafeUnpin for WorkerUnprotectGuard
impl UnwindSafe for WorkerUnprotectGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more