Skip to main content

altrep_data1_mut

Function altrep_data1_mut 

Source
pub unsafe fn altrep_data1_mut<T: TypedExternal>(
    x: SEXP,
) -> Option<&'static mut T>
Expand description

Get a mutable reference to data in ALTREP data1 slot via ErasedExternalPtr.

This is useful for ALTREP methods that need to mutate the underlying data.

§Safety

  • x must be a valid ALTREP SEXP
  • Must be called from the R main thread
  • The caller must ensure no other references to the data exist

§Example

fn dataptr(x: SEXP, _writable: bool) -> *mut c_void {
    match unsafe { altrep_data1_mut::<MyData>(x) } {
        Some(data) => data.buffer.as_mut_ptr().cast(),
        None => core::ptr::null_mut(),
    }
}