Skip to main content

r_slice

Function r_slice 

Source
pub(crate) unsafe fn r_slice<'a, T>(ptr: *const T, len: usize) -> &'a [T]
Expand description

Create a slice from an R data pointer, handling the zero-length case.

R returns a sentinel pointer (0x1) instead of null for empty vectors (e.g., LOGICAL(integer(0))0x1). Rust 1.93+ validates pointer alignment in slice::from_raw_parts even for len == 0, so passing R’s sentinel directly causes a precondition-check abort.

This helper returns an empty slice for len == 0 without touching the pointer.

§Safety

If len > 0, ptr must satisfy the requirements of std::slice::from_raw_parts.