Skip to main content

miniextendr_api/altrep_data/
iter.rs

1//! Iterator-backed ALTREP data adaptors.
2//!
3//! Provides lazy backing data for ALTREP vectors from Rust iterators. Elements
4//! are generated on-demand and cached for repeat access.
5//!
6//! ## Data adaptors, not R-facing vectors
7//!
8//! The `*Data` types in these submodules implement only the data-level traits
9//! ([`AltrepLen`](crate::altrep_data::AltrepLen) + the matching `Alt*Data`
10//! trait). They do **not** implement
11//! [`RegisterAltrep`](crate::altrep::RegisterAltrep), so they cannot back a
12//! live R SEXP by themselves. To expose one to R, wrap it in a concrete
13//! struct deriving the matching `Altrep*` derive with `#[altrep(manual)]` and
14//! delegate the data-trait methods to the inner adaptor (the derive cannot be
15//! applied to the adaptors directly because they are generic over the
16//! iterator type):
17//!
18//! ```ignore
19//! use miniextendr_api::altrep_data::{AltIntegerData, AltrepLen, IterIntData};
20//!
21//! #[derive(miniextendr_api::AltrepInteger)]
22//! #[altrep(class = "MyLazyInts", manual)]
23//! struct MyLazyInts {
24//!     inner: IterIntData<Box<dyn Iterator<Item = i32>>>,
25//! }
26//!
27//! impl AltrepLen for MyLazyInts {
28//!     fn len(&self) -> usize {
29//!         self.inner.len()
30//!     }
31//! }
32//!
33//! impl AltIntegerData for MyLazyInts {
34//!     fn elt(&self, i: usize) -> i32 {
35//!         self.inner.elt(i)
36//!     }
37//! }
38//! ```
39//!
40//! ## Submodules
41//!
42//! - [`state`]: Core `IterState<I, T>` + standard data adaptors (Int, Real, Logical, Raw)
43//! - [`coerce`]: Coerced variants (`IterIntCoerceData`, `IterRealCoerceData`, `IterIntFromBoolData`)
44//!   plus the String/List/Complex data adaptors (`IterStringData`, `IterListData`, `IterComplexData`)
45//! - [`sparse`]: Sparse iterators using `nth()` for skip-ahead (`SparseIterState`)
46//! - [`windowed`]: Sliding-window iterators (`WindowedIterState`)
47
48mod coerce;
49mod sparse;
50mod state;
51mod windowed;
52
53pub use coerce::*;
54pub use sparse::*;
55pub use state::*;
56pub use windowed::*;