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 altrep_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 buffer;
38mod builtins;
39mod core;
40mod deque;
41mod iter;
42/// Helper macros for implementing ALTREP data traits.
43pub mod macros;
44mod stream;
45mod traits;
46
47pub use buffer::AltrepBuffer;
48pub(crate) use core::fill_region;
49pub use core::{
50    AltrepDataptr, AltrepExtract, AltrepExtractSubset, AltrepLen, AltrepSerialize, InferBase,
51    Logical, Sortedness, altrep_values_written, materialize_altrep_data2,
52    materialized_altrep_data2, materialized_altrep_region,
53};
54pub use iter::*;
55pub use stream::*;
56pub use traits::*;
57
58#[cfg(test)]
59mod tests;