Skip to main content

miniextendr_api/
altrep_data.rs

1//! High-level ALTREP data traits.
2//!
3//! These traits let you implement ALTREP behavior using `&self` methods instead of
4//! raw `SEXP` callbacks. The library provides blanket implementations that handle
5//! the SEXP extraction automatically.
6//!
7//! ## Quick Start
8//!
9//! For common types, just use them directly:
10//!
11//! ```ignore
12//! // Vec<i32> already implements AltIntegerData
13//! let altrep = create_altinteger(vec![1, 2, 3, 4, 5]);
14//! ```
15//!
16//! For custom types, implement the relevant trait:
17//!
18//! ```ignore
19//! struct Fibonacci { len: usize }
20//!
21//! impl AltrepLen for Fibonacci {
22//!     fn len(&self) -> usize { self.len }
23//! }
24//!
25//! impl AltIntegerData for Fibonacci {
26//!     fn elt(&self, i: usize) -> i32 {
27//!         // Compute fibonacci(i)
28//!         unimplemented!()
29//!     }
30//! }
31//! ```
32//!
33//! For simple field-based types, the `Altrep*` derive macros provide a shorter path:
34//! they auto-implement `AltrepLen` and the matching `Alt*Data` trait, and can
35//! optionally call the low-level `impl_alt*_from_data!` helpers.
36
37mod builtins;
38mod core;
39mod iter;
40/// Helper macros for implementing ALTREP data traits.
41pub mod macros;
42mod stream;
43mod traits;
44
45pub(crate) use core::fill_region;
46pub use core::{
47    AltrepDataptr, AltrepExtract, AltrepExtractSubset, AltrepLen, AltrepSerialize, InferBase,
48    Logical, Sortedness, materialize_altrep_data2,
49};
50pub use iter::*;
51pub use stream::*;
52pub use traits::*;
53
54#[cfg(test)]
55mod tests;