Skip to main content

RNativeType

Trait RNativeType 

Source
pub trait RNativeType:
    Sized
    + Copy
    + 'static {
    const SEXP_TYPE: SEXPTYPE;

    // Required methods
    unsafe fn dataptr_mut(sexp: SEXP) -> *mut Self;
    fn elt(sexp: SEXP, i: isize) -> Self;
}
Expand description

Marker trait for types that correspond to R’s native vector element types.

This enables blanket implementations for TryFromSexp and safe conversions.

Required Associated Constants§

Source

const SEXP_TYPE: SEXPTYPE

The SEXPTYPE for vectors containing this element type.

Required Methods§

Source

unsafe fn dataptr_mut(sexp: SEXP) -> *mut Self

Get mutable pointer to vector data.

For empty vectors (length 0), returns an aligned dangling pointer rather than R’s internal 0x1 sentinel, which isn’t properly aligned for most types. This allows safe creation of zero-length slices with std::slice::from_raw_parts_mut.

§Safety
  • sexp must be a valid, non-null SEXP of the corresponding vector type.
  • For ALTREP vectors, this may trigger materialization.
Source

fn elt(sexp: SEXP, i: isize) -> Self

Read the i-th element via the appropriate *_ELT accessor.

Goes through R’s ALTREP dispatch for ALTREP vectors.

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.

Implementations on Foreign Types§

Source§

impl RNativeType for f64

Source§

const SEXP_TYPE: SEXPTYPE = SEXPTYPE::REALSXP

Source§

unsafe fn dataptr_mut(sexp: SEXP) -> *mut Self

Source§

fn elt(sexp: SEXP, i: isize) -> Self

Source§

impl RNativeType for i32

Source§

const SEXP_TYPE: SEXPTYPE = SEXPTYPE::INTSXP

Source§

unsafe fn dataptr_mut(sexp: SEXP) -> *mut Self

Source§

fn elt(sexp: SEXP, i: isize) -> Self

Source§

impl RNativeType for u8

Source§

const SEXP_TYPE: SEXPTYPE = SEXPTYPE::RAWSXP

Source§

unsafe fn dataptr_mut(sexp: SEXP) -> *mut Self

Source§

fn elt(sexp: SEXP, i: isize) -> Self

Implementors§

Source§

impl RNativeType for RLogical

Source§

const SEXP_TYPE: SEXPTYPE = SEXPTYPE::LGLSXP

Source§

impl RNativeType for Rcomplex

Source§

const SEXP_TYPE: SEXPTYPE = SEXPTYPE::CPLXSXP