miniextendr_api/altrep_data/
macros.rs1#[macro_export]
14#[doc(hidden)]
15macro_rules! __impl_inferbase {
16 ($ty:ty, $base:ident, $make_fn:path, $install_fn:ident) => {
17 impl $crate::altrep_data::InferBase for $ty {
18 const BASE: $crate::altrep::RBase = $crate::altrep::RBase::$base;
19
20 unsafe fn make_class(
21 class_name: *const i8,
22 pkg_name: *const i8,
23 ) -> $crate::ffi::altrep::R_altrep_class_t {
24 let dll = $crate::altrep_dll_info();
27 let cls = unsafe { $make_fn(class_name, pkg_name, dll) };
28 let name = unsafe { ::core::ffi::CStr::from_ptr(class_name) };
29 $crate::altrep::validate_altrep_class(cls, name, $crate::altrep::RBase::$base)
30 }
31
32 unsafe fn install_methods(cls: $crate::ffi::altrep::R_altrep_class_t) {
33 unsafe { $crate::altrep_bridge::install_base::<$ty>(cls) };
34 unsafe { $crate::altrep_bridge::install_vec::<$ty>(cls) };
35 unsafe { $crate::altrep_bridge::$install_fn::<$ty>(cls) };
36 }
37 }
38 };
39}
40
41#[macro_export]
43macro_rules! impl_inferbase_integer {
44 ($ty:ty) => {
45 $crate::__impl_inferbase!(
46 $ty,
47 Int,
48 $crate::ffi::altrep::R_make_altinteger_class,
49 install_int
50 );
51 };
52}
53
54#[macro_export]
56macro_rules! impl_inferbase_real {
57 ($ty:ty) => {
58 $crate::__impl_inferbase!(
59 $ty,
60 Real,
61 $crate::ffi::altrep::R_make_altreal_class,
62 install_real
63 );
64 };
65}
66
67#[macro_export]
69macro_rules! impl_inferbase_logical {
70 ($ty:ty) => {
71 $crate::__impl_inferbase!(
72 $ty,
73 Logical,
74 $crate::ffi::altrep::R_make_altlogical_class,
75 install_lgl
76 );
77 };
78}
79
80#[macro_export]
82macro_rules! impl_inferbase_raw {
83 ($ty:ty) => {
84 $crate::__impl_inferbase!(
85 $ty,
86 Raw,
87 $crate::ffi::altrep::R_make_altraw_class,
88 install_raw
89 );
90 };
91}
92
93#[macro_export]
95macro_rules! impl_inferbase_string {
96 ($ty:ty) => {
97 $crate::__impl_inferbase!(
98 $ty,
99 String,
100 $crate::ffi::altrep::R_make_altstring_class,
101 install_str
102 );
103 };
104}
105
106#[macro_export]
108macro_rules! impl_inferbase_complex {
109 ($ty:ty) => {
110 $crate::__impl_inferbase!(
111 $ty,
112 Complex,
113 $crate::ffi::altrep::R_make_altcomplex_class,
114 install_cplx
115 );
116 };
117}
118
119#[macro_export]
121macro_rules! impl_inferbase_list {
122 ($ty:ty) => {
123 $crate::__impl_inferbase!(
124 $ty,
125 List,
126 $crate::ffi::altrep::R_make_altlist_class,
127 install_list
128 );
129 };
130}
131
132#[cfg(test)]
134mod tests;
135