Skip to main content

AltrepDataptr

Trait AltrepDataptr 

Source
pub trait AltrepDataptr<T> {
    // Required method
    fn dataptr(&mut self, writable: bool) -> Option<*mut T>;

    // Provided method
    fn dataptr_or_null(&self) -> Option<*const T> { ... }
}
Expand description

Trait for ALTREP types that can expose a data pointer.

§Writability contract

When writable = true, R will write through the returned pointer (e.g., x[i] <- val). The implementation must ensure:

  1. The returned pointer is safe to write to (not read-only memory).
  2. Writes are visible to subsequent Elt/Get_region calls (no stale cache).

For owned containers (Vec<T>, Box<[T]>), this is automatic because DATAPTR and Elt both access the same allocation (data1).

For copy-on-write types (Cow<'static, [T]>), writable = true should trigger the copy so writes go to owned memory. When writable = false, the borrowed pointer can be returned directly.

For immutable data (&'static [T]), writable = true should panic or return None since the data cannot be modified.

The __impl_altvec_dataptr macro uses dataptr_or_null for read-only access and only calls dataptr(&mut self, true) when R requests a writable pointer.

Required Methods§

Source

fn dataptr(&mut self, writable: bool) -> Option<*mut T>

Get a pointer to the underlying data, possibly triggering materialization.

When writable is true, R will write through the returned pointer. Implementations for immutable data should panic or return None.

Return None if data cannot be accessed as a contiguous buffer.

Provided Methods§

Source

fn dataptr_or_null(&self) -> Option<*const T>

Get a read-only pointer without forcing materialization.

Return None if data is not already materialized or cannot provide a contiguous buffer. R will fall back to element-by-element access via Elt when this returns None.

The __impl_altvec_dataptr macro calls this for Dataptr(x, writable=false) to avoid unnecessary mutable borrows and copy-on-write overhead.

Implementations on Foreign Types§

Source§

impl AltrepDataptr<f64> for Cow<'static, [f64]>

Source§

fn dataptr(&mut self, writable: bool) -> Option<*mut f64>

Source§

fn dataptr_or_null(&self) -> Option<*const f64>

Source§

impl AltrepDataptr<f64> for Box<[f64]>

Source§

fn dataptr(&mut self, _writable: bool) -> Option<*mut f64>

Source§

fn dataptr_or_null(&self) -> Option<*const f64>

Source§

impl AltrepDataptr<f64> for Vec<f64>

Source§

fn dataptr(&mut self, _writable: bool) -> Option<*mut f64>

Source§

fn dataptr_or_null(&self) -> Option<*const f64>

Source§

impl AltrepDataptr<f64> for Range<f64>

Source§

fn dataptr(&mut self, _writable: bool) -> Option<*mut f64>

Source§

impl AltrepDataptr<i32> for Cow<'static, [i32]>

Source§

fn dataptr(&mut self, writable: bool) -> Option<*mut i32>

Source§

fn dataptr_or_null(&self) -> Option<*const i32>

Source§

impl AltrepDataptr<i32> for Box<[i32]>

Source§

fn dataptr(&mut self, _writable: bool) -> Option<*mut i32>

Source§

fn dataptr_or_null(&self) -> Option<*const i32>

Source§

impl AltrepDataptr<i32> for Vec<i32>

Source§

fn dataptr(&mut self, _writable: bool) -> Option<*mut i32>

Source§

fn dataptr_or_null(&self) -> Option<*const i32>

Source§

impl AltrepDataptr<i32> for Range<i32>

Source§

fn dataptr(&mut self, _writable: bool) -> Option<*mut i32>

Source§

impl AltrepDataptr<i32> for Range<i64>

Source§

fn dataptr(&mut self, _writable: bool) -> Option<*mut i32>

Source§

impl AltrepDataptr<u8> for Cow<'static, [u8]>

Source§

fn dataptr(&mut self, writable: bool) -> Option<*mut u8>

Source§

fn dataptr_or_null(&self) -> Option<*const u8>

Source§

impl AltrepDataptr<u8> for Box<[u8]>

Source§

fn dataptr(&mut self, _writable: bool) -> Option<*mut u8>

Source§

fn dataptr_or_null(&self) -> Option<*const u8>

Source§

impl AltrepDataptr<u8> for Vec<u8>

Source§

fn dataptr(&mut self, _writable: bool) -> Option<*mut u8>

Source§

fn dataptr_or_null(&self) -> Option<*const u8>

Source§

impl AltrepDataptr<RLogical> for Box<[bool]>

Source§

fn dataptr(&mut self, _writable: bool) -> Option<*mut RLogical>

Source§

impl AltrepDataptr<RLogical> for Vec<bool>

Source§

fn dataptr(&mut self, _writable: bool) -> Option<*mut RLogical>

Source§

impl AltrepDataptr<Rcomplex> for Cow<'static, [Rcomplex]>

Source§

impl AltrepDataptr<Rcomplex> for Box<[Rcomplex]>

Source§

impl AltrepDataptr<Rcomplex> for Vec<Rcomplex>

Implementors§