Skip to main content

Module altrep_data

Module altrep_data 

Source
Expand description

High-level ALTREP data traits.

These traits let you implement ALTREP behavior using &self methods instead of raw SEXP callbacks. The library provides blanket implementations that handle the SEXP extraction automatically.

ยงQuick Start

For common types, just use them directly:

โ“˜
// Vec<i32> already implements AltIntegerData
let altrep = create_altinteger(vec![1, 2, 3, 4, 5]);

For custom types, implement the relevant trait:

โ“˜
struct Fibonacci { len: usize }

impl AltrepLen for Fibonacci {
    fn altrep_len(&self) -> usize { self.len }
}

impl AltIntegerData for Fibonacci {
    fn elt(&self, i: usize) -> i32 {
        // Compute fibonacci(i)
        unimplemented!()
    }
}

For simple field-based types, the Altrep* derive macros provide a shorter path: they auto-implement AltrepLen and the matching Alt*Data trait, and can optionally call the low-level impl_alt*_from_data! helpers.

Re-exportsยง

pub use buffer::AltrepBuffer;
pub(crate) use core::fill_region; ๐Ÿ”’
pub use core::AltrepDataptr;
pub use core::AltrepExtract;
pub use core::AltrepExtractSubset;
pub use core::AltrepLen;
pub use core::AltrepSerialize;
pub use core::InferBase;
pub use core::Logical;
pub use core::Sortedness;
pub use core::altrep_values_written;
pub use core::materialize_altrep_data2;
pub use core::materialized_altrep_data2;
pub use core::materialized_altrep_region;
pub use iter::*;
pub use stream::*;
pub use traits::*;

Modulesยง

buffer ๐Ÿ”’
Native Vec ownership that preserves allocations already exposed to R.
builtins ๐Ÿ”’
Built-in ALTREP data implementations for standard Rust types.
core ๐Ÿ”’
Core ALTREP data traits and helpers.
deque ๐Ÿ”’
ALTREP storage for native-element ring buffers.
iter ๐Ÿ”’
Iterator-backed ALTREP data adaptors.
macros
Helper macros for implementing ALTREP data traits. Convenience macros for implementing InferBase.
stream ๐Ÿ”’
Streaming ALTREP data adaptors backed by chunk-cached reader closures.
traits ๐Ÿ”’
Per-family ALTREP data traits.