pub trait AltrepExtract: Sized {
// Required methods
unsafe fn altrep_extract_ref(x: SEXP) -> &'static Self;
unsafe fn altrep_extract_mut(x: SEXP) -> &'static mut Self;
}Expand description
How to extract a reference to Self from an ALTREP SEXP’s data1 slot.
The default implementation (for types that implement TypedExternal) extracts
via ExternalPtr<T> downcast from data1. Power users who want native SEXP
storage can implement this trait manually.
§Safety
Implementations must ensure that the returned references are valid for the duration of the ALTREP callback (i.e., the SEXP is protected by R’s GC).
§Panics
The blanket implementation panics if ExternalPtr extraction fails (type
mismatch, null pointer, etc.). This is a programmer error, not a runtime
condition. Callers must ensure the ALTREP SEXP was created with the correct
data type. The panic is caught by the ALTREP guard (RustUnwind or RUnwind)
and converted to an R error. Using AltrepGuard::Unsafe with a type that
can fail extraction is unsound.
Required Methods§
Sourceunsafe fn altrep_extract_ref(x: SEXP) -> &'static Self
unsafe fn altrep_extract_ref(x: SEXP) -> &'static Self
Extract a shared reference from the ALTREP data1 slot.
§Safety
xmust be a valid ALTREP SEXP whose data1 holds data of typeSelf- Must be called from R’s main thread
Sourceunsafe fn altrep_extract_mut(x: SEXP) -> &'static mut Self
unsafe fn altrep_extract_mut(x: SEXP) -> &'static mut Self
Extract a mutable reference from the ALTREP data1 slot.
§Safety
xmust be a valid ALTREP SEXP whose data1 holds data of typeSelf- Must be called from R’s main thread
- The caller must ensure no other references to the data exist
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<T: TypedExternal> AltrepExtract for T
Blanket implementation for types stored in ExternalPtr (the common case).
This is the default storage strategy: data1 is an EXTPTRSXP wrapping a
Box<Box<dyn Any>> that downcasts to &T.