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§
Sourceconst R_NA: Self
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).
f64→NA_REAL(R’s canonical NA double bit pattern, not a plainNaN)i32→i32::MIN(NA_INTEGER)RLogical→RLogical::NA(NA_LOGICAL)Rcomplex→ both partsNA_REALu8(RAWSXP) →0— R’s raw type has no NA, so absent positions become0x00rather than a missing marker.
Required Methods§
Sourceunsafe fn dataptr_mut(sexp: SEXP) -> *mut Self
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
sexpmust be a valid, non-null SEXP of the corresponding vector type.- For ALTREP vectors, this may trigger materialization.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".