Skip to main content

ErasedExternalPtr

Type Alias ErasedExternalPtr 

Source
pub type ErasedExternalPtr = ExternalPtr<()>;
Expand description

Type-erased ExternalPtr for cases where the concrete T is not needed.

Aliased Type§

#[repr(C)]
pub struct ErasedExternalPtr { sexp: SEXP, cached_ptr: NonNull<()>, root: Option<ProtectKey>, _marker: PhantomData<()>, }

Fields§

§sexp: SEXP§cached_ptr: NonNull<()>

Cached data pointer, set once at construction time.

This avoids the R_ExternalPtrAddr FFI call on every as_ref()/as_mut(). The pointer remains valid for the lifetime of the ExternalPtr because:

  • R’s finalizer only runs after R garbage-collects the SEXP (which cannot happen while a Rust ExternalPtr value exists).
  • R_ClearExternalPtr is only called in methods that consume or finalize (into_raw, into_inner, release_any).
§root: Option<ProtectKey>

The ProtectPool key rooting this handle’s EXTPTRSXP, or None for borrowed views.

Some(key) for owning handles built from a fresh value (new / new_unchecked / from_raw / Clone / Default): the constructor roots the EXTPTRSXP in the main-thread pool so it stays alive for the whole Rust lifetime of the handle — including while it sits in a Vec across other R allocations before being handed to R (#836). Drop / into_raw / into_inner release the root via the key.

None for borrowed views of an SEXP R already owns (wrap_sexp* / from_sexp* / reborrow): no root is taken, so none is released. The aliased object is kept alive by whatever R-side reference handed it to us (a .Call argument frame, an owning sibling handle, …).

§_marker: PhantomData<()>

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 32 bytes