Expand description
Derive macros for ALTREP data traits.
These macros auto-implement AltrepLen and Alt*Data traits for simple field-based
ALTREP types, reducing boilerplate for users.
§Two paths: field-based vs manual
#[derive(AltrepInteger)] (and the Real / Logical / Raw / String
/ Complex / List variants) drive one of two code paths:
-
Field-based (default) — point the derive at struct fields that hold the vector length and a constant element value:
ⓘ#[derive(AltrepInteger)] #[altrep(len = "n", elt = "value", class = "Repeat")] struct Repeat { n: usize, value: i32 }The derive emits
AltrepLen,AltIntegerData,Altrep,AltVec,RegisterAltrep, and theR_make_altinteger_classregistration. No extra trait impls required. -
Manual —
#[altrep(manual)]suppressesAltrepLen/AltIntegerDatageneration so you can write the element-access logic yourself. The low-level trait impls (Altrep,AltVec, family methods,InferBase) are still emitted —#[altrep(no_lowlevel)]is the additional escape hatch when you also want to controlAltrep/AltVecdirectly.
Pick by what your data looks like: a finite buffer that fits in a struct
field → field-based; a computed element (fibonacci(i)) → manual.
§Guard mode attribute
The derive recognises #[altrep(unsafe)] / #[altrep(rust_unwind)] /
#[altrep(r_unwind)] on the struct, which sets the runtime
Altrep::GUARD const that the trampolines in altrep_bridge dispatch
on. Default is r_unwind (safe for callbacks that call R APIs).
§Derive validation rules
Several #[altrep(...)] options conflict; the derive rejects illegal
combinations at compile time:
| Option | Allowed on families | Conflicts with |
|---|---|---|
subset | all atomic (integer, real, logical, raw, string, complex) | dataptr, list |
dataptr | integer, real, logical, raw, string, complex | subset, list |
serialize | all | (none) |
manual | all | (none — turns off AltrepLen/Alt*Data generation) |
no_lowlevel | all | (none — also suppresses the low-level trait impls) |
The list family rejects dataptr and subset — list elements are
arbitrary SEXPs, so there is no contiguous buffer to expose.
Structs§
- Altrep
Attrs 🔒 - Parsed
#[altrep(...)]attributes controlling ALTREP derive code generation. - Altrep
Family 🔒Config - Per-family configuration controlling low-level code generation for an ALTREP type family.
Functions§
- derive_
altrep_ complex - Derive macro entry point for
AltrepComplex. - derive_
altrep_ 🔒generic - Shared implementation for all non-list ALTREP derive macros.
- derive_
altrep_ integer - Derive macro entry point for
AltrepInteger. - derive_
altrep_ list - Derive macro entry point for
AltrepList. - derive_
altrep_ logical - Derive macro entry point for
AltrepLogical. - derive_
altrep_ raw - Derive macro entry point for
AltrepRaw. - derive_
altrep_ real - Derive macro entry point for
AltrepReal. - derive_
altrep_ string - Derive macro entry point for
AltrepString. - generate_
altrep_ 🔒len - Generates an
impl AltrepLen for Tblock that delegates to a named struct field.