Skip to main content

Module altrep

Module altrep 

Source
Expand description

Core ALTREP types and registration traits.

§Architecture

  • FFI: Raw setters/types in crate::sys::altrep
  • Traits: Safe traits in crate::altrep_traits (Altrep, AltVec, AltInteger, etc.)
    • Required methods: Compiler-enforced by trait definition
    • Optional methods: Gated by HAS_* constants, defaults provided
  • Bridge: Generic extern "C-unwind" trampolines in crate::altrep_bridge
  • High-level data traits: crate::altrep_data (AltrepLen + Alt*Data) — implement with &self methods instead of raw SEXP.
  • SEXP wrapper: crate::altrep_sexp!Send + !Sync wrapper that prevents an ALTREP SEXP from crossing thread boundaries before materialization.
  • Derive: #[derive(AltrepInteger)] / AltrepReal / AltrepLogical / AltrepRaw / AltrepString / AltrepComplex / AltrepList on a struct emits everything below: Altrep, AltVec, the family-specific trait, AltrepLen, Alt*Data, an impl RegisterAltrep, and the R_make_alt* registration. See the altrep_derive module in the miniextendr-macros crate for the attribute reference and validation rules.

§Two code paths

  1. Field-based derive (default) — annotate fields with #[altrep(len = "field", elt = "field", class = "Name")] and the derive handles length/elt/registration.
  2. Manual#[altrep(manual)] skips AltrepLen / Alt*Data so you hand-roll those traits (custom elt, no_na, sum, …); the impl_alt*_from_data! registration is still emitted.

Both paths route trampolines through the same guard mode selected by Altrep::GUARD; guard modes are documented on crate::altrep_traits.

§Threading

ALTREP callbacks run on R’s main thread — they receive raw SEXP arguments which are not Send. Do not route them through the worker thread; the trampolines bridge from C straight back into safe Rust on the main thread, with panic / longjmp handling per the chosen guard mode.

Enums§

RBase
Base type for ALTREP vectors.

Statics§

REGISTERED_CLASS_NAMES 🔒
Records every ALTREP class name registered during package_init().

Traits§

AltrepClass
Trait implemented by ALTREP classes via #[miniextendr].
RegisterAltrep
Registration trait: implemented per type by the macro on struct items.

Functions§

assert_altrep_class_uniqueness
Assert that all registered ALTREP class names are unique.
make_class_by_base
Create an ALTREP class handle based on the runtime base type.
validate_altrep_class
Validate that an ALTREP class handle was successfully created.