pub struct OwnedProtect {
sexp: SEXP,
armed: bool,
_nosend: PhantomData<Rc<()>>,
}Expand description
A single-object RAII guard: PROTECT on create, UNPROTECT(1) on drop.
Use this for simple cases where you’re protecting a single value and
don’t need the batching benefits of ProtectScope.
§Example
ⓘ
unsafe fn allocate_and_fill() -> SEXP {
let guard = OwnedProtect::new(Rf_allocVector(REALSXP, 10));
fill_vector(guard.get());
// Return the SEXP - guard drops and unprotects on this line.
// This is safe because no GC can occur between unprotect and return.
guard.get()
}§Warning: Stack Ordering
OwnedProtect uses UNPROTECT(1), which removes the top of the protection
stack. If you have nested protections from other sources, the drop order matters!
For complex scenarios, prefer ProtectScope which unprotects all its values
at once when dropped.
Fields§
§sexp: SEXP§armed: bool§_nosend: PhantomData<Rc<()>>Implementations§
Trait Implementations§
Source§impl Deref for OwnedProtect
impl Deref for OwnedProtect
Auto Trait Implementations§
impl Freeze for OwnedProtect
impl RefUnwindSafe for OwnedProtect
impl !Send for OwnedProtect
impl !Sync for OwnedProtect
impl Unpin for OwnedProtect
impl UnsafeUnpin for OwnedProtect
impl UnwindSafe for OwnedProtect
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