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 incrate::altrep_bridge - High-level data traits:
crate::altrep_data(AltrepLen+Alt*Data) — implement with&selfmethods instead of raw SEXP. - SEXP wrapper:
crate::altrep_sexp—!Send + !Syncwrapper that prevents an ALTREP SEXP from crossing thread boundaries before materialization. - Derive:
#[derive(AltrepInteger)]/AltrepReal/AltrepLogical/AltrepRaw/AltrepString/AltrepComplex/AltrepListon a struct emits everything below:Altrep,AltVec, the family-specific trait,AltrepLen,Alt*Data, animpl RegisterAltrep, and theR_make_alt*registration. See thealtrep_derivemodule in theminiextendr-macroscrate for the attribute reference and validation rules.
§Two code paths
- Field-based derive (default) — annotate fields with
#[altrep(len = "field", elt = "field", class = "Name")]and the derive handleslength/elt/registration. - Manual —
#[altrep(manual)]skipsAltrepLen/Alt*Dataso you hand-roll those traits (customelt,no_na,sum, …); theimpl_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§
- Altrep
Class - Trait implemented by ALTREP classes via
#[miniextendr]. - Register
Altrep - 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.