Skip to main content

miniextendr_api/
prelude.rs

1//! Convenience re-exports for common miniextendr items.
2//!
3//! A single `use miniextendr_api::prelude::*;` brings into scope the most
4//! commonly used macros, traits, types, and helpers so user crates can avoid
5//! a long list of individual imports.
6//!
7//! ## Optional feature types
8//!
9//! When a Cargo feature is enabled (e.g., `uuid`, `regex`, `ndarray`), the
10//! prelude includes both the miniextendr adapter types **and** a re-export of
11//! the upstream dependency crate itself. This means you do **not** need to add
12//! optional crates as direct dependencies in your `Cargo.toml` — enabling the
13//! feature on `miniextendr-api` is enough.
14//!
15//! ```toml
16//! [dependencies]
17//! miniextendr-api = { version = "0.1", features = ["uuid", "ndarray"] }
18//! # No need for: uuid = "1", ndarray = "0.16"
19//! ```
20//!
21//! Access the upstream crate via the prelude:
22//!
23//! ```ignore
24//! use miniextendr_api::prelude::*;
25//!
26//! // Uuid is re-exported from the uuid crate
27//! let id = Uuid::new_v4();
28//!
29//! // The full crate is also available for advanced usage
30//! let parsed = uuid::Uuid::parse_str("...").unwrap();
31//! ```
32//!
33//! # Example
34//!
35//! ```ignore
36//! use miniextendr_api::prelude::*;
37//!
38//! #[miniextendr]
39//! fn add(a: i32, b: i32) -> i32 {
40//!     a + b
41//! }
42//! ```
43
44// region: Proc-macro re-exports
45pub use crate::{
46    // Derive macros
47    Altrep,
48    ExternalPtr,
49    MatchArg,
50    RFactor,
51    list,
52    miniextendr,
53    typed_dataframe,
54    typed_list,
55};
56// endregion
57
58// region: Core traits
59pub use crate::{Coerce, IntoR, IntoRAltrep, TryCoerce, TryFromSexp};
60// endregion
61
62// region: Types
63pub use crate::{
64    IntoList, Lazy, List, ListBuilder, ListMut, Missing, NamedVector, OwnedProtect, ProtectScope,
65    Protected, ProtectedStrVec, RCow, StrVec, StrVecBuilder,
66};
67// endregion
68
69// region: DataFrame family
70//
71// The row/group-level data-frame surface: the owned type, its error, the
72// conversion trait pair, and the `#[derive(DataFrameRow)]` macro. Group-level
73// items (`GroupedDataFrame`, `GroupKey`, `group_rows`) stay at the crate root
74// — `df.group_by(..)` returns them without the caller naming the types.
75pub use crate::{DataFrame, DataFrameError, DataFrameRow, FromDataFrame, IntoDataFrame};
76// endregion
77
78// region: Worker thread
79pub use crate::{Sendable, with_r_thread};
80// endregion
81
82// region: Error handling and console output
83pub use crate::{r_print, r_println, r_warning};
84// endregion
85
86// region: R evaluation
87//
88// `r!` / `r_str!` evaluate R source from Rust; `r_eval_str` is the underlying
89// protect-safe parse + eval function they expand to.
90pub use crate::expression::r_eval_str;
91pub use crate::{r, r_str};
92// endregion
93
94// region: Safe R-value surface
95//
96// `SEXP` is the central newtype; `SexpExt` is the ergonomic extension trait
97// that provides the safe higher-level methods. The type vocabulary
98// (`SEXPTYPE`, `R_xlen_t`, `RLogical`, `Rboolean`, `Rcomplex`, `RNativeType`,
99// …) is **not** re-exported here — those are lower-level types that user
100// code should reach for explicitly at the crate root
101// (`miniextendr_api::SEXPTYPE`, `miniextendr_api::R_xlen_t`, …) when
102// genuinely needed (rare; common in tests and macro-generated code).
103// `miniextendr_api::sys::*` is the raw-FFI escape hatch — `extern
104// "C-unwind"` symbols and the ALTREP method type aliases only. The prelude
105// is for the abstraction surface, not the raw R C API.
106pub use crate::{SEXP, SexpExt};
107// endregion
108
109// region: Optional feature re-exports
110
111// --- either ---
112#[cfg(feature = "either")]
113pub use crate::{Either, Left, Right};
114
115#[cfg(feature = "either")]
116pub use either;
117
118// --- uuid ---
119#[cfg(feature = "uuid")]
120pub use crate::{RUuidOps, Uuid};
121#[cfg(feature = "uuid")]
122pub use uuid;
123
124// --- regex ---
125#[cfg(feature = "regex")]
126pub use crate::{CaptureGroups, RRegexOps, Regex};
127#[cfg(feature = "regex")]
128pub use regex;
129
130// --- url ---
131#[cfg(feature = "url")]
132pub use crate::{RUrlOps, Url};
133#[cfg(feature = "url")]
134pub use url;
135
136// --- time ---
137#[cfg(feature = "time")]
138pub use crate::{Date, Duration, OffsetDateTime, RDuration};
139#[cfg(feature = "time")]
140pub use time;
141
142// --- ordered-float ---
143#[cfg(feature = "ordered-float")]
144pub use crate::{OrderedFloat, ROrderedFloatOps};
145#[cfg(feature = "ordered-float")]
146pub use ordered_float;
147
148// --- num-bigint ---
149#[cfg(feature = "num-bigint")]
150pub use crate::{BigInt, BigUint, RBigIntOps, RBigUintOps};
151#[cfg(feature = "num-bigint")]
152pub use num_bigint;
153
154// --- rust_decimal ---
155#[cfg(feature = "rust_decimal")]
156pub use crate::{Decimal, RDecimalOps};
157#[cfg(feature = "rust_decimal")]
158pub use rust_decimal;
159
160// --- num-complex ---
161#[cfg(feature = "num-complex")]
162pub use crate::{Complex, RComplexOps};
163#[cfg(feature = "num-complex")]
164pub use num_complex;
165
166// --- num-traits ---
167#[cfg(feature = "num-traits")]
168pub use crate::{RFloat, RNum, RSigned};
169#[cfg(feature = "num-traits")]
170pub use num_traits;
171
172// --- ndarray ---
173#[cfg(feature = "ndarray")]
174pub use crate::{
175    Array1, Array2, Array3, Array4, Array5, Array6, ArrayD, ArrayView1, ArrayView2, ArrayViewD,
176    ArrayViewMut1, ArrayViewMut2, ArrayViewMutD, RNdArrayOps,
177};
178#[cfg(feature = "ndarray")]
179pub use ndarray;
180
181// --- nalgebra ---
182#[cfg(feature = "nalgebra")]
183pub use crate::{DMatrix, DVector, RMatrixOps, RVectorOps, SMatrix, SVector};
184#[cfg(feature = "nalgebra")]
185pub use nalgebra;
186
187// --- indexmap ---
188#[cfg(feature = "indexmap")]
189pub use crate::{IndexMap, RIndexMapOps};
190#[cfg(feature = "indexmap")]
191pub use indexmap;
192
193// --- rayon ---
194#[cfg(feature = "rayon")]
195pub use crate::{RParallelExtend, RParallelIterator};
196#[cfg(feature = "rayon")]
197pub use rayon;
198
199// --- rand ---
200#[cfg(feature = "rand")]
201pub use crate::{RDistributionOps, RDistributions, RRng, RRngOps};
202#[cfg(feature = "rand")]
203pub use rand;
204#[cfg(feature = "rand_distr")]
205pub use rand_distr;
206
207// --- serde (direct R serialization) ---
208#[cfg(feature = "serde")]
209pub use crate::serde::{AsSerialize, RDeserializeNative, RSerializeNative};
210#[cfg(feature = "serde")]
211pub use serde;
212
213// --- serde_json ---
214#[cfg(feature = "serde_json")]
215pub use crate::{JsonOptions, JsonValue, RDeserialize, RSerialize};
216#[cfg(feature = "serde_json")]
217pub use serde_json;
218
219// --- toml ---
220#[cfg(feature = "toml")]
221pub use crate::{TomlValue, toml_from_str, toml_to_string};
222#[cfg(feature = "toml")]
223pub use toml;
224
225// --- bytes ---
226#[cfg(feature = "bytes")]
227pub use crate::{Bytes, BytesMut, RBuf, RBufMut};
228#[cfg(feature = "bytes")]
229pub use bytes;
230
231// --- aho-corasick ---
232#[cfg(feature = "aho-corasick")]
233pub use crate::{AhoCorasick, aho_compile};
234#[cfg(feature = "aho-corasick")]
235pub use aho_corasick;
236
237// --- bitflags ---
238#[cfg(feature = "bitflags")]
239pub use crate::RFlags;
240#[cfg(feature = "bitflags")]
241pub use bitflags;
242
243// --- bitvec ---
244#[cfg(feature = "bitvec")]
245pub use crate::RBitVec;
246#[cfg(feature = "bitvec")]
247pub use bitvec;
248
249// --- borsh ---
250#[cfg(feature = "borsh")]
251pub use crate::{Borsh, RBorshOps};
252#[cfg(feature = "borsh")]
253pub use borsh;
254
255// --- raw_conversions ---
256#[cfg(feature = "raw_conversions")]
257pub use crate::{Pod, Raw, RawSlice, Zeroable};
258#[cfg(feature = "raw_conversions")]
259pub use bytemuck;
260
261// --- sha2 ---
262#[cfg(feature = "sha2")]
263pub use crate::{sha256_bytes, sha256_str, sha512_bytes, sha512_str};
264#[cfg(feature = "sha2")]
265pub use sha2;
266
267// --- tabled ---
268#[cfg(feature = "tabled")]
269pub use crate::{Table, Tabled, table_to_string};
270#[cfg(feature = "tabled")]
271pub use tabled;
272
273// --- tinyvec ---
274#[cfg(feature = "tinyvec")]
275pub use crate::{ArrayVec, TinyVec};
276#[cfg(feature = "tinyvec")]
277pub use tinyvec;
278
279// --- indicatif ---
280#[cfg(feature = "indicatif")]
281pub use crate::progress;
282#[cfg(feature = "indicatif")]
283pub use indicatif;
284
285// --- vctrs ---
286#[cfg(feature = "vctrs")]
287pub use crate::{IntoVctrs, VctrsClass};
288// endregion