Skip to main content

altrep_data1_as

Function altrep_data1_as 

Source
pub unsafe fn altrep_data1_as<T: TypedExternal>(
    x: SEXP,
) -> Option<ExternalPtr<T>>
Expand description

Extract the ALTREP data1 slot as a typed ExternalPtr<T>.

This is a convenience function for ALTREP implementations that store their data in an ExternalPtr in the data1 slot.

§Safety

  • x must be a valid ALTREP SEXP
  • Must be called from the R main thread

§Example

impl Altrep for MyAltrepClass {
    const HAS_LENGTH: bool = true;
    fn length(x: SEXP) -> R_xlen_t {
        match unsafe { altrep_data1_as::<MyData>(x) } {
            Some(ext) => ext.data.len() as R_xlen_t,
            None => 0,
        }
    }
}