Skip to main content

Protector

Trait Protector 

Source
pub trait Protector {
    // Required method
    unsafe fn protect(&mut self, sexp: SEXP) -> SEXP;
}
Expand description

A scope-like GC protection backend.

Functions that allocate multiple intermediate SEXPs can take &mut impl Protector to be generic over the protection mechanism. All protected SEXPs stay protected until the protector itself is dropped — there is no individual release via this trait.

For individual release by key, use ProtectPool::insert and ProtectPool::release directly.

§Safety

Implementations must ensure that the returned SEXP remains protected from GC for at least as long as the protector is alive. Callers must not use the returned SEXP after the protector is dropped.

All methods must be called from the R main thread.

Required Methods§

Source

unsafe fn protect(&mut self, sexp: SEXP) -> SEXP

Protect a SEXP from garbage collection.

Returns the same SEXP (for convenience in chaining). The SEXP is now protected and will remain so until the protector is dropped.

The key (if any) is managed internally — use the pool’s direct API (insert/release) if you need individual release.

§Safety

Must be called from the R main thread. sexp must be a valid SEXP.

Implementors§