Skip to main content

AltrepSexp

Struct AltrepSexp 

Source
pub struct AltrepSexp {
    sexp: SEXP,
    _not_send: PhantomData<Rc<()>>,
}
Expand description

A SEXP known to be ALTREP. !Send + !Sync — must be materialized on the R main thread before data can be accessed or sent to other threads.

This type prevents ALTREP vectors from being accidentally sent to rayon or other worker threads where DATAPTR_RO would invoke R internals (undefined behavior).

§As a #[miniextendr] parameter

AltrepSexp implements TryFromSexp, so it can be used directly as a function parameter. It only accepts ALTREP vectors — non-ALTREP input produces an error.

#[miniextendr]
pub fn altrep_info(x: AltrepSexp) -> String {
    format!("{:?}, len={}", x.sexptype(), x.len())
}
altrep_info(1:10)          # OK — 1:10 is ALTREP
altrep_info(c(1L, 2L, 3L)) # Error: "expected an ALTREP vector"

§Construction

§Materialization

All materialization methods must be called on the R main thread.

§Thread safety

AltrepSexp is !Send + !Sync (via PhantomData<Rc<()>>). This is a compile-time guarantee: you cannot send an un-materialized ALTREP vector to another thread. Call one of the materialize_* methods first to get a Send + Sync slice or SEXP.

Fields§

§sexp: SEXP§_not_send: PhantomData<Rc<()>>

PhantomData<Rc<()>> makes this type !Send + !Sync.

Implementations§

Source§

impl AltrepSexp

Source

pub unsafe fn from_raw(sexp: SEXP) -> Self

Wrap a SEXP that is known to be ALTREP.

§Safety

Caller must ensure ALTREP(sexp) is true (non-zero).

Source

pub fn try_wrap(sexp: SEXP) -> Option<Self>

Check a SEXP and wrap if ALTREP. Returns None if not ALTREP.

Source

pub unsafe fn materialize(self) -> SEXP

Force materialization and return the (now materialized) SEXP.

For contiguous types (INTSXP, REALSXP, LGLSXP, RAWSXP, CPLXSXP), calls DATAPTR_RO to trigger ALTREP materialization. For STRSXP, iterates STRING_ELT to force element materialization.

After this call, the SEXP’s data pointer is stable and can be safely accessed from any thread (the SEXP itself is still Send + Sync).

§Safety

Must be called on the R main thread.

Source

pub unsafe fn materialize_real(&self) -> &[f64]

Materialize and return a typed slice of f64 (REALSXP).

§Safety

Must be called on the R main thread. The SEXP must be REALSXP.

Source

pub unsafe fn materialize_integer(&self) -> &[i32]

Materialize and return a typed slice of i32 (INTSXP).

§Safety

Must be called on the R main thread. The SEXP must be INTSXP.

Source

pub unsafe fn materialize_logical(&self) -> &[i32]

Materialize and return a typed slice of i32 (LGLSXP, R’s internal logical storage).

§Safety

Must be called on the R main thread. The SEXP must be LGLSXP.

Source

pub unsafe fn materialize_raw(&self) -> &[u8]

Materialize and return a typed slice of u8 (RAWSXP).

§Safety

Must be called on the R main thread. The SEXP must be RAWSXP.

Source

pub unsafe fn materialize_complex(&self) -> &[Rcomplex]

Materialize and return a typed slice of Rcomplex (CPLXSXP).

§Safety

Must be called on the R main thread. The SEXP must be CPLXSXP.

Source

pub unsafe fn materialize_strings(&self) -> Vec<Option<String>>

Materialize strings into owned Rust data.

Each element is None for NA_character_, or Some(String) otherwise.

§Safety

Must be called on the R main thread. The SEXP must be STRSXP.

Source

pub unsafe fn as_raw(&self) -> SEXP

Get the inner SEXP without materializing.

§Safety

The returned SEXP is still ALTREP. Do not call DATAPTR_RO on it from a non-R thread.

Source

pub fn sexptype(&self) -> SEXPTYPE

Get the SEXPTYPE of the underlying vector.

Source

pub fn len(&self) -> usize

Get the length of the underlying vector.

Source

pub fn is_empty(&self) -> bool

Check if the underlying vector is empty.

Trait Implementations§

Source§

impl Debug for AltrepSexp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl IntoR for AltrepSexp

Convert AltrepSexp to R by returning the inner SEXP.

This allows AltrepSexp to be used as a return type from #[miniextendr] functions, transparently passing the ALTREP SEXP back to R.

Source§

type Error = Infallible

The error type for fallible conversions. Read more
Source§

fn try_into_sexp(self) -> Result<SEXP, Self::Error>

Try to convert this value to an R SEXP. Read more
Source§

unsafe fn try_into_sexp_unchecked(self) -> Result<SEXP, Self::Error>

Try to convert to SEXP without thread safety checks. Read more
Source§

fn into_sexp(self) -> SEXP

Convert this value to an R SEXP, panicking on error. Read more
Source§

unsafe fn into_sexp_unchecked(self) -> SEXP
where Self: Sized,

Convert to SEXP without thread safety checks, panicking on error. Read more
Source§

impl TryFromSexp for AltrepSexp

Conversion from R SEXP to AltrepSexp.

Only succeeds if the input is an ALTREP vector (ALTREP(sexp) != 0). Non-ALTREP input produces SexpError::InvalidValue.

This is the inverse of TryFromSexp for SEXP, which accepts any SEXP but auto-materializes ALTREP.

Source§

type Error = SexpError

The error type returned when conversion fails.
Source§

fn try_from_sexp(sexp: SEXP) -> Result<Self, Self::Error>

Attempt to convert an R SEXP to this Rust type. Read more
Source§

unsafe fn try_from_sexp_unchecked(sexp: SEXP) -> Result<Self, Self::Error>

Convert from SEXP without thread safety checks. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> RDebug for T
where T: Debug,

Source§

fn debug_str(&self) -> String

Get a compact debug string representation.
Source§

fn debug_str_pretty(&self) -> String

Get a pretty-printed debug string with indentation.
Source§

impl<T> SizeEq<Cell<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<ManuallyDrop<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<MaybeUninit<T>> for T

Source§

impl<T> SizeEq<ReadOnly<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromReadOnly

Source§

impl<T> SizeEq<T> for T
where T: ?Sized,

Source§

impl<T> SizeEq<Unalign<T>> for T

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<UnsafeCell<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<Wrapping<T>> for T

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> InvariantsEq<ManuallyDrop<T>> for T
where T: ?Sized,

Source§

impl<T> InvariantsEq<T> for T
where T: ?Sized,

Source§

impl<T> InvariantsEq<Unalign<T>> for T

Source§

impl<T> InvariantsEq<Wrapping<T>> for T

Source§

impl<Src, Dst, A, SV, DV, R> MutationCompatible<Src, A, SV, DV, (BecauseRead, R)> for Dst
where A: Aliasing, SV: Validity, DV: Validity, Src: Read<A, R> + ?Sized, Dst: Read<A, R> + ?Sized,

Source§

impl<Src, Dst, A, SV, DV> MutationCompatible<Src, A, SV, DV, BecauseInvariantsEq> for Dst
where A: Aliasing, SV: Validity, DV: Validity, Src: TransmuteFrom<Dst, DV, SV> + ?Sized, Dst: TransmuteFrom<Src, SV, DV> + InvariantsEq<Src> + ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<Cell<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<ManuallyDrop<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<ReadOnly<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<Src, Dst> TransmuteFrom<Src, Initialized, Initialized> for Dst
where Src: ?Sized, Dst: ?Sized,

Source§

impl<Src, Dst, V> TransmuteFrom<Src, V, Uninit> for Dst
where V: Validity, Src: ?Sized, Dst: ?Sized,

Source§

impl<Src, Dst> TransmuteFrom<Src, Valid, Initialized> for Dst
where Src: IntoBytes + ?Sized, Dst: ?Sized,

Source§

impl<T> TransmuteFrom<Unalign<T>, Valid, Valid> for T

Source§

impl<T> TransmuteFrom<UnsafeCell<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<Wrapping<T>, Valid, Valid> for T

Source§

impl<Src, Dst, A, SV, DV, C, R> TransmuteFromPtr<Src, A, SV, DV, C, R> for Dst
where A: Aliasing, SV: Validity, DV: Validity, C: CastExact<Src, Dst>, Dst: TransmuteFrom<Src, SV, DV> + TryTransmuteFromPtr<Src, A, SV, DV, C, R> + ?Sized, Src: ?Sized,

Source§

impl<Src, Dst, SV, DV, A, C, R> TryTransmuteFromPtr<Src, A, SV, DV, C, (BecauseMutationCompatible, R)> for Dst
where A: Aliasing, SV: Validity, DV: Validity, Src: TransmuteFrom<Dst, DV, SV> + ?Sized, Dst: MutationCompatible<Src, A, SV, DV, R> + ?Sized, C: CastExact<Src, Dst>,

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 8 bytes