Skip to main content

miniextendr_api/ffi/
altrep.rs

1//! Raw ALTREP C API bindings.
2//!
3//! This module mirrors `R_ext/Altrep.h` and is intentionally low-level.
4
5#![allow(non_camel_case_types)]
6use crate::ffi::{DllInfo, R_xlen_t, Rboolean, Rbyte, Rcomplex, SEXP, SEXPTYPE};
7
8/// Signature for ALTREP `coerce` method.
9pub type R_altrep_Coerce_method_t =
10    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, rtype: SEXPTYPE) -> SEXP>;
11
12/// Signature for ALTREP extended `unserialize` method.
13pub type R_altrep_UnserializeEX_method_t = ::std::option::Option<
14    unsafe extern "C-unwind" fn(
15        class: SEXP,
16        state: SEXP,
17        attr: SEXP,
18        objf: ::std::os::raw::c_int,
19        levs: ::std::os::raw::c_int,
20    ) -> SEXP,
21>;
22/// Signature for ALTREP `unserialize` method.
23pub type R_altrep_Unserialize_method_t =
24    ::std::option::Option<unsafe extern "C-unwind" fn(class: SEXP, state: SEXP) -> SEXP>;
25/// Signature for ALTREP `serialized_state` method.
26pub type R_altrep_Serialized_state_method_t =
27    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP) -> SEXP>;
28/// Signature for ALTREP extended `duplicate` method.
29pub type R_altrep_DuplicateEX_method_t =
30    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, deep: Rboolean) -> SEXP>;
31/// Signature for ALTREP `duplicate` method.
32pub type R_altrep_Duplicate_method_t =
33    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, deep: Rboolean) -> SEXP>;
34/// Signature for ALTREP `inspect` method.
35pub type R_altrep_Inspect_method_t = ::std::option::Option<
36    unsafe extern "C-unwind" fn(
37        x: SEXP,
38        pre: ::std::os::raw::c_int,
39        deep: ::std::os::raw::c_int,
40        pvec: ::std::os::raw::c_int,
41        inspect_subtree: ::std::option::Option<
42            unsafe extern "C-unwind" fn(
43                x: SEXP,
44                pre: ::std::os::raw::c_int,
45                deep: ::std::os::raw::c_int,
46                pvec: ::std::os::raw::c_int,
47            ),
48        >,
49    ) -> Rboolean,
50>;
51/// Signature for ALTREP `length` method.
52pub type R_altrep_Length_method_t =
53    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP) -> R_xlen_t>;
54/// Signature for ALTVEC `dataptr` method.
55pub type R_altvec_Dataptr_method_t = ::std::option::Option<
56    unsafe extern "C-unwind" fn(x: SEXP, writable: Rboolean) -> *mut ::std::os::raw::c_void,
57>;
58/// Signature for ALTVEC `dataptr_or_null` method.
59pub type R_altvec_Dataptr_or_null_method_t =
60    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP) -> *const ::std::os::raw::c_void>;
61/// Signature for ALTVEC `extract_subset` method.
62pub type R_altvec_Extract_subset_method_t =
63    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, indx: SEXP, call: SEXP) -> SEXP>;
64/// Signature for ALTINTEGER `elt` method.
65pub type R_altinteger_Elt_method_t = ::std::option::Option<
66    unsafe extern "C-unwind" fn(x: SEXP, i: R_xlen_t) -> ::std::os::raw::c_int,
67>;
68/// Signature for ALTINTEGER `get_region` method.
69pub type R_altinteger_Get_region_method_t = ::std::option::Option<
70    unsafe extern "C-unwind" fn(
71        sx: SEXP,
72        i: R_xlen_t,
73        n: R_xlen_t,
74        buf: *mut ::std::os::raw::c_int,
75    ) -> R_xlen_t,
76>;
77/// Signature for ALTINTEGER `is_sorted` method.
78pub type R_altinteger_Is_sorted_method_t =
79    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP) -> ::std::os::raw::c_int>;
80/// Signature for ALTINTEGER `no_na` method.
81pub type R_altinteger_No_NA_method_t =
82    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP) -> ::std::os::raw::c_int>;
83/// Signature for ALTINTEGER `sum` method.
84pub type R_altinteger_Sum_method_t =
85    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, narm: Rboolean) -> SEXP>;
86/// Signature for ALTINTEGER `min` method.
87pub type R_altinteger_Min_method_t =
88    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, narm: Rboolean) -> SEXP>;
89/// Signature for ALTINTEGER `max` method.
90pub type R_altinteger_Max_method_t =
91    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, narm: Rboolean) -> SEXP>;
92/// Signature for ALTREAL `elt` method.
93pub type R_altreal_Elt_method_t =
94    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, i: R_xlen_t) -> f64>;
95/// Signature for ALTREAL `get_region` method.
96pub type R_altreal_Get_region_method_t = ::std::option::Option<
97    unsafe extern "C-unwind" fn(sx: SEXP, i: R_xlen_t, n: R_xlen_t, buf: *mut f64) -> R_xlen_t,
98>;
99/// Signature for ALTREAL `is_sorted` method.
100pub type R_altreal_Is_sorted_method_t =
101    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP) -> ::std::os::raw::c_int>;
102/// Signature for ALTREAL `no_na` method.
103pub type R_altreal_No_NA_method_t =
104    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP) -> ::std::os::raw::c_int>;
105/// Signature for ALTREAL `sum` method.
106pub type R_altreal_Sum_method_t =
107    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, narm: Rboolean) -> SEXP>;
108/// Signature for ALTREAL `min` method.
109pub type R_altreal_Min_method_t =
110    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, narm: Rboolean) -> SEXP>;
111/// Signature for ALTREAL `max` method.
112pub type R_altreal_Max_method_t =
113    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, narm: Rboolean) -> SEXP>;
114/// Signature for ALTLOGICAL `elt` method.
115pub type R_altlogical_Elt_method_t = ::std::option::Option<
116    unsafe extern "C-unwind" fn(x: SEXP, i: R_xlen_t) -> ::std::os::raw::c_int,
117>;
118/// Signature for ALTLOGICAL `get_region` method.
119pub type R_altlogical_Get_region_method_t = ::std::option::Option<
120    unsafe extern "C-unwind" fn(
121        sx: SEXP,
122        i: R_xlen_t,
123        n: R_xlen_t,
124        buf: *mut ::std::os::raw::c_int,
125    ) -> R_xlen_t,
126>;
127/// Signature for ALTLOGICAL `is_sorted` method.
128pub type R_altlogical_Is_sorted_method_t =
129    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP) -> ::std::os::raw::c_int>;
130/// Signature for ALTLOGICAL `no_na` method.
131pub type R_altlogical_No_NA_method_t =
132    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP) -> ::std::os::raw::c_int>;
133/// Signature for ALTLOGICAL `sum` method.
134pub type R_altlogical_Sum_method_t =
135    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, narm: Rboolean) -> SEXP>;
136/// Signature for ALTRAW `elt` method.
137pub type R_altraw_Elt_method_t =
138    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, i: R_xlen_t) -> Rbyte>;
139/// Signature for ALTRAW `get_region` method.
140pub type R_altraw_Get_region_method_t = ::std::option::Option<
141    unsafe extern "C-unwind" fn(sx: SEXP, i: R_xlen_t, n: R_xlen_t, buf: *mut Rbyte) -> R_xlen_t,
142>;
143/// Signature for ALTCOMPLEX `elt` method.
144pub type R_altcomplex_Elt_method_t =
145    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, i: R_xlen_t) -> Rcomplex>;
146/// Signature for ALTCOMPLEX `get_region` method.
147pub type R_altcomplex_Get_region_method_t = ::std::option::Option<
148    unsafe extern "C-unwind" fn(sx: SEXP, i: R_xlen_t, n: R_xlen_t, buf: *mut Rcomplex) -> R_xlen_t,
149>;
150/// Signature for ALTSTRING `elt` method.
151pub type R_altstring_Elt_method_t =
152    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, i: R_xlen_t) -> SEXP>;
153/// Signature for ALTSTRING `set_elt` method.
154pub type R_altstring_Set_elt_method_t =
155    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, i: R_xlen_t, v: SEXP)>;
156/// Signature for ALTSTRING `is_sorted` method.
157pub type R_altstring_Is_sorted_method_t =
158    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP) -> ::std::os::raw::c_int>;
159/// Signature for ALTSTRING `no_na` method.
160pub type R_altstring_No_NA_method_t =
161    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP) -> ::std::os::raw::c_int>;
162/// Signature for ALTLIST `elt` method.
163pub type R_altlist_Elt_method_t =
164    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, i: R_xlen_t) -> SEXP>;
165/// Signature for ALTLIST `set_elt` method.
166pub type R_altlist_Set_elt_method_t =
167    ::std::option::Option<unsafe extern "C-unwind" fn(x: SEXP, i: R_xlen_t, v: SEXP)>;
168#[derive(Clone, Copy)]
169#[repr(C)]
170/// Opaque ALTREP class handle.
171pub struct R_altrep_class_t {
172    /// Underlying class object SEXP.
173    pub ptr: SEXP,
174}
175
176// SAFETY: R_altrep_class_t is only used on R's main thread.
177// The class is created once during package init and stored in a static.
178unsafe impl Send for R_altrep_class_t {}
179unsafe impl Sync for R_altrep_class_t {}
180
181// Imported ALTREP constructor and method-registration symbols.
182#[allow(missing_docs)]
183#[miniextendr_macros::r_ffi_checked]
184unsafe extern "C-unwind" {
185    // ALTREP instance construction (encapsulated by R_altrep_class_t::new_altrep)
186    fn R_new_altrep(aclass: R_altrep_class_t, data1: SEXP, data2: SEXP) -> SEXP;
187
188    // ALTREP class constructors — pub because proc-macro generates calls from user crates
189    pub fn R_make_altstring_class(
190        cname: *const ::std::os::raw::c_char,
191        pname: *const ::std::os::raw::c_char,
192        info: *mut DllInfo,
193    ) -> R_altrep_class_t;
194    pub fn R_make_altinteger_class(
195        cname: *const ::std::os::raw::c_char,
196        pname: *const ::std::os::raw::c_char,
197        info: *mut DllInfo,
198    ) -> R_altrep_class_t;
199    pub fn R_make_altreal_class(
200        cname: *const ::std::os::raw::c_char,
201        pname: *const ::std::os::raw::c_char,
202        info: *mut DllInfo,
203    ) -> R_altrep_class_t;
204    pub fn R_make_altlogical_class(
205        cname: *const ::std::os::raw::c_char,
206        pname: *const ::std::os::raw::c_char,
207        info: *mut DllInfo,
208    ) -> R_altrep_class_t;
209    pub fn R_make_altraw_class(
210        cname: *const ::std::os::raw::c_char,
211        pname: *const ::std::os::raw::c_char,
212        info: *mut DllInfo,
213    ) -> R_altrep_class_t;
214    pub fn R_make_altcomplex_class(
215        cname: *const ::std::os::raw::c_char,
216        pname: *const ::std::os::raw::c_char,
217        info: *mut DllInfo,
218    ) -> R_altrep_class_t;
219    pub fn R_make_altlist_class(
220        cname: *const ::std::os::raw::c_char,
221        pname: *const ::std::os::raw::c_char,
222        info: *mut DllInfo,
223    ) -> R_altrep_class_t;
224    // ALTREP class membership check (encapsulated by R_altrep_class_t::inherits)
225    fn R_altrep_inherits(x: SEXP, aclass: R_altrep_class_t) -> Rboolean;
226
227    // Method setters — private, encapsulated by R_altrep_class_t methods
228    fn R_set_altrep_UnserializeEX_method(
229        cls: R_altrep_class_t,
230        fun: R_altrep_UnserializeEX_method_t,
231    );
232    fn R_set_altrep_Unserialize_method(cls: R_altrep_class_t, fun: R_altrep_Unserialize_method_t);
233    fn R_set_altrep_Serialized_state_method(
234        cls: R_altrep_class_t,
235        fun: R_altrep_Serialized_state_method_t,
236    );
237    fn R_set_altrep_DuplicateEX_method(cls: R_altrep_class_t, fun: R_altrep_DuplicateEX_method_t);
238    fn R_set_altrep_Duplicate_method(cls: R_altrep_class_t, fun: R_altrep_Duplicate_method_t);
239    fn R_set_altrep_Coerce_method(cls: R_altrep_class_t, fun: R_altrep_Coerce_method_t);
240    fn R_set_altrep_Inspect_method(cls: R_altrep_class_t, fun: R_altrep_Inspect_method_t);
241    fn R_set_altrep_Length_method(cls: R_altrep_class_t, fun: R_altrep_Length_method_t);
242    fn R_set_altvec_Dataptr_method(cls: R_altrep_class_t, fun: R_altvec_Dataptr_method_t);
243    fn R_set_altvec_Dataptr_or_null_method(
244        cls: R_altrep_class_t,
245        fun: R_altvec_Dataptr_or_null_method_t,
246    );
247    fn R_set_altvec_Extract_subset_method(
248        cls: R_altrep_class_t,
249        fun: R_altvec_Extract_subset_method_t,
250    );
251    fn R_set_altinteger_Elt_method(cls: R_altrep_class_t, fun: R_altinteger_Elt_method_t);
252    fn R_set_altinteger_Get_region_method(
253        cls: R_altrep_class_t,
254        fun: R_altinteger_Get_region_method_t,
255    );
256    fn R_set_altinteger_Is_sorted_method(
257        cls: R_altrep_class_t,
258        fun: R_altinteger_Is_sorted_method_t,
259    );
260    fn R_set_altinteger_No_NA_method(cls: R_altrep_class_t, fun: R_altinteger_No_NA_method_t);
261    fn R_set_altinteger_Sum_method(cls: R_altrep_class_t, fun: R_altinteger_Sum_method_t);
262    fn R_set_altinteger_Min_method(cls: R_altrep_class_t, fun: R_altinteger_Min_method_t);
263    fn R_set_altinteger_Max_method(cls: R_altrep_class_t, fun: R_altinteger_Max_method_t);
264    fn R_set_altreal_Elt_method(cls: R_altrep_class_t, fun: R_altreal_Elt_method_t);
265    fn R_set_altreal_Get_region_method(cls: R_altrep_class_t, fun: R_altreal_Get_region_method_t);
266    fn R_set_altreal_Is_sorted_method(cls: R_altrep_class_t, fun: R_altreal_Is_sorted_method_t);
267    fn R_set_altreal_No_NA_method(cls: R_altrep_class_t, fun: R_altreal_No_NA_method_t);
268    fn R_set_altreal_Sum_method(cls: R_altrep_class_t, fun: R_altreal_Sum_method_t);
269    fn R_set_altreal_Min_method(cls: R_altrep_class_t, fun: R_altreal_Min_method_t);
270    fn R_set_altreal_Max_method(cls: R_altrep_class_t, fun: R_altreal_Max_method_t);
271    fn R_set_altlogical_Elt_method(cls: R_altrep_class_t, fun: R_altlogical_Elt_method_t);
272    fn R_set_altlogical_Get_region_method(
273        cls: R_altrep_class_t,
274        fun: R_altlogical_Get_region_method_t,
275    );
276    fn R_set_altlogical_Is_sorted_method(
277        cls: R_altrep_class_t,
278        fun: R_altlogical_Is_sorted_method_t,
279    );
280    fn R_set_altlogical_No_NA_method(cls: R_altrep_class_t, fun: R_altlogical_No_NA_method_t);
281    fn R_set_altlogical_Sum_method(cls: R_altrep_class_t, fun: R_altlogical_Sum_method_t);
282    fn R_set_altraw_Elt_method(cls: R_altrep_class_t, fun: R_altraw_Elt_method_t);
283    fn R_set_altraw_Get_region_method(cls: R_altrep_class_t, fun: R_altraw_Get_region_method_t);
284    fn R_set_altcomplex_Elt_method(cls: R_altrep_class_t, fun: R_altcomplex_Elt_method_t);
285    fn R_set_altcomplex_Get_region_method(
286        cls: R_altrep_class_t,
287        fun: R_altcomplex_Get_region_method_t,
288    );
289    fn R_set_altstring_Elt_method(cls: R_altrep_class_t, fun: R_altstring_Elt_method_t);
290    fn R_set_altstring_Set_elt_method(cls: R_altrep_class_t, fun: R_altstring_Set_elt_method_t);
291    fn R_set_altstring_Is_sorted_method(cls: R_altrep_class_t, fun: R_altstring_Is_sorted_method_t);
292    fn R_set_altstring_No_NA_method(cls: R_altrep_class_t, fun: R_altstring_No_NA_method_t);
293    fn R_set_altlist_Elt_method(cls: R_altrep_class_t, fun: R_altlist_Elt_method_t);
294    fn R_set_altlist_Set_elt_method(cls: R_altrep_class_t, fun: R_altlist_Set_elt_method_t);
295}
296
297impl R_altrep_class_t {
298    /// Create from a raw SEXP pointer.
299    ///
300    /// Rust equivalent of C macro `R_SUBTYPE_INIT(x)`.
301    #[inline(always)]
302    pub const fn from_sexp(ptr: SEXP) -> Self {
303        Self { ptr }
304    }
305
306    /// Get the underlying SEXP.
307    ///
308    /// Rust equivalent of C macro `R_SEXP(x)`.
309    #[inline(always)]
310    pub fn as_sexp(self) -> SEXP {
311        self.ptr
312    }
313
314    /// Create a new ALTREP instance with data1 and data2 slots.
315    ///
316    /// # Safety
317    /// Must be called on R's main thread. `data1` and `data2` must be valid SEXPs.
318    #[inline]
319    pub unsafe fn new_altrep(self, data1: SEXP, data2: SEXP) -> SEXP {
320        unsafe { R_new_altrep(self, data1, data2) }
321    }
322
323    /// Create a new ALTREP instance (no thread check).
324    ///
325    /// # Safety
326    /// Must be called on R's main thread.
327    #[inline]
328    pub unsafe fn new_altrep_unchecked(self, data1: SEXP, data2: SEXP) -> SEXP {
329        unsafe { R_new_altrep_unchecked(self, data1, data2) }
330    }
331
332    /// Check if `x` is an instance of this ALTREP class.
333    ///
334    /// # Safety
335    /// Must be called on R's main thread. `x` must be a valid SEXP.
336    #[inline]
337    pub unsafe fn inherits(self, x: SEXP) -> bool {
338        unsafe { R_altrep_inherits(x, self) != Rboolean::FALSE }
339    }
340
341    // region: Base ALTREP method setters
342
343    /// Set the Length method.
344    /// # Safety
345    /// Must be called during R initialization.
346    #[inline]
347    pub unsafe fn set_length_method(self, fun: R_altrep_Length_method_t) {
348        unsafe { R_set_altrep_Length_method(self, fun) }
349    }
350
351    /// Set the Serialized_state method.
352    /// # Safety
353    /// Must be called during R initialization.
354    #[inline]
355    pub unsafe fn set_serialized_state_method(self, fun: R_altrep_Serialized_state_method_t) {
356        unsafe { R_set_altrep_Serialized_state_method(self, fun) }
357    }
358
359    /// Set the Unserialize method.
360    /// # Safety
361    /// Must be called during R initialization.
362    #[inline]
363    pub unsafe fn set_unserialize_method(self, fun: R_altrep_Unserialize_method_t) {
364        unsafe { R_set_altrep_Unserialize_method(self, fun) }
365    }
366
367    /// Set the UnserializeEX method.
368    /// # Safety
369    /// Must be called during R initialization.
370    #[inline]
371    pub unsafe fn set_unserialize_ex_method(self, fun: R_altrep_UnserializeEX_method_t) {
372        unsafe { R_set_altrep_UnserializeEX_method(self, fun) }
373    }
374
375    /// Set the Duplicate method.
376    /// # Safety
377    /// Must be called during R initialization.
378    #[inline]
379    pub unsafe fn set_duplicate_method(self, fun: R_altrep_Duplicate_method_t) {
380        unsafe { R_set_altrep_Duplicate_method(self, fun) }
381    }
382
383    /// Set the DuplicateEX method.
384    /// # Safety
385    /// Must be called during R initialization.
386    #[inline]
387    pub unsafe fn set_duplicate_ex_method(self, fun: R_altrep_DuplicateEX_method_t) {
388        unsafe { R_set_altrep_DuplicateEX_method(self, fun) }
389    }
390
391    /// Set the Coerce method.
392    /// # Safety
393    /// Must be called during R initialization.
394    #[inline]
395    pub unsafe fn set_coerce_method(self, fun: R_altrep_Coerce_method_t) {
396        unsafe { R_set_altrep_Coerce_method(self, fun) }
397    }
398
399    /// Set the Inspect method.
400    /// # Safety
401    /// Must be called during R initialization.
402    #[inline]
403    pub unsafe fn set_inspect_method(self, fun: R_altrep_Inspect_method_t) {
404        unsafe { R_set_altrep_Inspect_method(self, fun) }
405    }
406
407    // endregion
408
409    // region: Vector-level method setters
410
411    /// Set the Dataptr method.
412    /// # Safety
413    /// Must be called during R initialization.
414    #[inline]
415    pub unsafe fn set_dataptr_method(self, fun: R_altvec_Dataptr_method_t) {
416        unsafe { R_set_altvec_Dataptr_method(self, fun) }
417    }
418
419    /// Set the Dataptr_or_null method.
420    /// # Safety
421    /// Must be called during R initialization.
422    #[inline]
423    pub unsafe fn set_dataptr_or_null_method(self, fun: R_altvec_Dataptr_or_null_method_t) {
424        unsafe { R_set_altvec_Dataptr_or_null_method(self, fun) }
425    }
426
427    /// Set the Extract_subset method.
428    /// # Safety
429    /// Must be called during R initialization.
430    #[inline]
431    pub unsafe fn set_extract_subset_method(self, fun: R_altvec_Extract_subset_method_t) {
432        unsafe { R_set_altvec_Extract_subset_method(self, fun) }
433    }
434
435    // endregion
436
437    // region: Integer method setters
438
439    /// Set the integer Elt method.
440    /// # Safety
441    /// Must be called during R initialization.
442    #[inline]
443    pub unsafe fn set_integer_elt_method(self, fun: R_altinteger_Elt_method_t) {
444        unsafe { R_set_altinteger_Elt_method(self, fun) }
445    }
446
447    /// Set the integer Get_region method.
448    /// # Safety
449    /// Must be called during R initialization.
450    #[inline]
451    pub unsafe fn set_integer_get_region_method(self, fun: R_altinteger_Get_region_method_t) {
452        unsafe { R_set_altinteger_Get_region_method(self, fun) }
453    }
454
455    /// Set the integer Is_sorted method.
456    /// # Safety
457    /// Must be called during R initialization.
458    #[inline]
459    pub unsafe fn set_integer_is_sorted_method(self, fun: R_altinteger_Is_sorted_method_t) {
460        unsafe { R_set_altinteger_Is_sorted_method(self, fun) }
461    }
462
463    /// Set the integer No_NA method.
464    /// # Safety
465    /// Must be called during R initialization.
466    #[inline]
467    pub unsafe fn set_integer_no_na_method(self, fun: R_altinteger_No_NA_method_t) {
468        unsafe { R_set_altinteger_No_NA_method(self, fun) }
469    }
470
471    /// Set the integer Sum method.
472    /// # Safety
473    /// Must be called during R initialization.
474    #[inline]
475    pub unsafe fn set_integer_sum_method(self, fun: R_altinteger_Sum_method_t) {
476        unsafe { R_set_altinteger_Sum_method(self, fun) }
477    }
478
479    /// Set the integer Min method.
480    /// # Safety
481    /// Must be called during R initialization.
482    #[inline]
483    pub unsafe fn set_integer_min_method(self, fun: R_altinteger_Min_method_t) {
484        unsafe { R_set_altinteger_Min_method(self, fun) }
485    }
486
487    /// Set the integer Max method.
488    /// # Safety
489    /// Must be called during R initialization.
490    #[inline]
491    pub unsafe fn set_integer_max_method(self, fun: R_altinteger_Max_method_t) {
492        unsafe { R_set_altinteger_Max_method(self, fun) }
493    }
494
495    // endregion
496
497    // region: Real method setters
498
499    /// Set the real Elt method.
500    /// # Safety
501    /// Must be called during R initialization.
502    #[inline]
503    pub unsafe fn set_real_elt_method(self, fun: R_altreal_Elt_method_t) {
504        unsafe { R_set_altreal_Elt_method(self, fun) }
505    }
506
507    /// Set the real Get_region method.
508    /// # Safety
509    /// Must be called during R initialization.
510    #[inline]
511    pub unsafe fn set_real_get_region_method(self, fun: R_altreal_Get_region_method_t) {
512        unsafe { R_set_altreal_Get_region_method(self, fun) }
513    }
514
515    /// Set the real Is_sorted method.
516    /// # Safety
517    /// Must be called during R initialization.
518    #[inline]
519    pub unsafe fn set_real_is_sorted_method(self, fun: R_altreal_Is_sorted_method_t) {
520        unsafe { R_set_altreal_Is_sorted_method(self, fun) }
521    }
522
523    /// Set the real No_NA method.
524    /// # Safety
525    /// Must be called during R initialization.
526    #[inline]
527    pub unsafe fn set_real_no_na_method(self, fun: R_altreal_No_NA_method_t) {
528        unsafe { R_set_altreal_No_NA_method(self, fun) }
529    }
530
531    /// Set the real Sum method.
532    /// # Safety
533    /// Must be called during R initialization.
534    #[inline]
535    pub unsafe fn set_real_sum_method(self, fun: R_altreal_Sum_method_t) {
536        unsafe { R_set_altreal_Sum_method(self, fun) }
537    }
538
539    /// Set the real Min method.
540    /// # Safety
541    /// Must be called during R initialization.
542    #[inline]
543    pub unsafe fn set_real_min_method(self, fun: R_altreal_Min_method_t) {
544        unsafe { R_set_altreal_Min_method(self, fun) }
545    }
546
547    /// Set the real Max method.
548    /// # Safety
549    /// Must be called during R initialization.
550    #[inline]
551    pub unsafe fn set_real_max_method(self, fun: R_altreal_Max_method_t) {
552        unsafe { R_set_altreal_Max_method(self, fun) }
553    }
554
555    // endregion
556
557    // region: Logical method setters
558
559    /// Set the logical Elt method.
560    /// # Safety
561    /// Must be called during R initialization.
562    #[inline]
563    pub unsafe fn set_logical_elt_method(self, fun: R_altlogical_Elt_method_t) {
564        unsafe { R_set_altlogical_Elt_method(self, fun) }
565    }
566
567    /// Set the logical Get_region method.
568    /// # Safety
569    /// Must be called during R initialization.
570    #[inline]
571    pub unsafe fn set_logical_get_region_method(self, fun: R_altlogical_Get_region_method_t) {
572        unsafe { R_set_altlogical_Get_region_method(self, fun) }
573    }
574
575    /// Set the logical Is_sorted method.
576    /// # Safety
577    /// Must be called during R initialization.
578    #[inline]
579    pub unsafe fn set_logical_is_sorted_method(self, fun: R_altlogical_Is_sorted_method_t) {
580        unsafe { R_set_altlogical_Is_sorted_method(self, fun) }
581    }
582
583    /// Set the logical No_NA method.
584    /// # Safety
585    /// Must be called during R initialization.
586    #[inline]
587    pub unsafe fn set_logical_no_na_method(self, fun: R_altlogical_No_NA_method_t) {
588        unsafe { R_set_altlogical_No_NA_method(self, fun) }
589    }
590
591    /// Set the logical Sum method.
592    /// # Safety
593    /// Must be called during R initialization.
594    #[inline]
595    pub unsafe fn set_logical_sum_method(self, fun: R_altlogical_Sum_method_t) {
596        unsafe { R_set_altlogical_Sum_method(self, fun) }
597    }
598
599    // endregion
600
601    // region: Raw method setters
602
603    /// Set the raw Elt method.
604    /// # Safety
605    /// Must be called during R initialization.
606    #[inline]
607    pub unsafe fn set_raw_elt_method(self, fun: R_altraw_Elt_method_t) {
608        unsafe { R_set_altraw_Elt_method(self, fun) }
609    }
610
611    /// Set the raw Get_region method.
612    /// # Safety
613    /// Must be called during R initialization.
614    #[inline]
615    pub unsafe fn set_raw_get_region_method(self, fun: R_altraw_Get_region_method_t) {
616        unsafe { R_set_altraw_Get_region_method(self, fun) }
617    }
618
619    // endregion
620
621    // region: Complex method setters
622
623    /// Set the complex Elt method.
624    /// # Safety
625    /// Must be called during R initialization.
626    #[inline]
627    pub unsafe fn set_complex_elt_method(self, fun: R_altcomplex_Elt_method_t) {
628        unsafe { R_set_altcomplex_Elt_method(self, fun) }
629    }
630
631    /// Set the complex Get_region method.
632    /// # Safety
633    /// Must be called during R initialization.
634    #[inline]
635    pub unsafe fn set_complex_get_region_method(self, fun: R_altcomplex_Get_region_method_t) {
636        unsafe { R_set_altcomplex_Get_region_method(self, fun) }
637    }
638
639    // endregion
640
641    // region: String method setters
642
643    /// Set the string Elt method.
644    /// # Safety
645    /// Must be called during R initialization.
646    #[inline]
647    pub unsafe fn set_string_elt_method(self, fun: R_altstring_Elt_method_t) {
648        unsafe { R_set_altstring_Elt_method(self, fun) }
649    }
650
651    /// Set the string Set_elt method.
652    /// # Safety
653    /// Must be called during R initialization.
654    #[inline]
655    pub unsafe fn set_string_set_elt_method(self, fun: R_altstring_Set_elt_method_t) {
656        unsafe { R_set_altstring_Set_elt_method(self, fun) }
657    }
658
659    /// Set the string Is_sorted method.
660    /// # Safety
661    /// Must be called during R initialization.
662    #[inline]
663    pub unsafe fn set_string_is_sorted_method(self, fun: R_altstring_Is_sorted_method_t) {
664        unsafe { R_set_altstring_Is_sorted_method(self, fun) }
665    }
666
667    /// Set the string No_NA method.
668    /// # Safety
669    /// Must be called during R initialization.
670    #[inline]
671    pub unsafe fn set_string_no_na_method(self, fun: R_altstring_No_NA_method_t) {
672        unsafe { R_set_altstring_No_NA_method(self, fun) }
673    }
674
675    // endregion
676
677    // region: List method setters
678
679    /// Set the list Elt method.
680    /// # Safety
681    /// Must be called during R initialization.
682    #[inline]
683    pub unsafe fn set_list_elt_method(self, fun: R_altlist_Elt_method_t) {
684        unsafe { R_set_altlist_Elt_method(self, fun) }
685    }
686
687    /// Set the list Set_elt method.
688    /// # Safety
689    /// Must be called during R initialization.
690    #[inline]
691    pub unsafe fn set_list_set_elt_method(self, fun: R_altlist_Set_elt_method_t) {
692        unsafe { R_set_altlist_Set_elt_method(self, fun) }
693    }
694
695    // endregion
696}
697
698// region: ALTREP Helper Functions (Rust equivalents of R's ALTREP macros)
699
700/// Extracts the `ptr` field from `R_altrep_class_t`.
701///
702/// Rust equivalent of the C macro `R_SEXP(x)` which expands to `(x).ptr`.
703#[inline(always)]
704pub fn sexp(class: R_altrep_class_t) -> SEXP {
705    class.ptr
706}
707
708/// Creates an `R_altrep_class_t` from a SEXP pointer.
709///
710/// Rust equivalent of the C macro `R_SUBTYPE_INIT(x)` which expands to `{ x }`.
711#[inline(always)]
712pub const fn subtype_init(ptr: SEXP) -> R_altrep_class_t {
713    R_altrep_class_t { ptr }
714}
715
716// endregion