Skip to main content

RNativeType

Trait RNativeType 

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

    // 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.

Source

const R_NA: Self

The per-type NA (missing-value) sentinel used when filling vector slots that have no source value (e.g. sparse scatter into a longer column).

  • f64NA_REAL (R’s canonical NA double bit pattern, not a plain NaN)
  • i32i32::MIN (NA_INTEGER)
  • RLogicalRLogical::NA (NA_LOGICAL)
  • Rcomplex → both parts NA_REAL
  • u8 (RAWSXP) → 0R’s raw type has no NA, so absent positions become 0x00 rather than a missing marker.

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".

Implementations on Foreign Types§

Source§

impl RNativeType for f64

Source§

const SEXP_TYPE: SEXPTYPE = SEXPTYPE::REALSXP

Source§

const R_NA: Self = NA_REAL

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§

const R_NA: Self = i32::MIN

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§

const R_NA: Self = 0

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§

const R_NA: Self = RLogical::NA

Source§

impl RNativeType for Rcomplex

Source§

const SEXP_TYPE: SEXPTYPE = SEXPTYPE::CPLXSXP

Source§

const R_NA: Self